java

Performance Cost of Profiling a Web-Application in Production

I am attempting to solve performance issues with a large and complex tomcat java web application. The biggest issue at the moment is that, from time to time, the memory usage spikes and the application becomes unresponsive. I've fixed everything I can fix with log profilers and Bayesian analysis of the log files. I'm considering running ...

Java - size of compression output-byteArray

When using the deflate-method of java.util.zip.Deflater, a byte[] has to be supplied as the argument, how big should that byte[] be initialized to? I've read there's no guarantee the compressed data will even be smaller that the uncompressed data. Is there a certain % of the input I should go with? Currently I make it twice as big as the...

Log4J rerouting of Log Events

I would like to build an Appender (or something similar) that inspects Events and on certain conditions creates logs new Events. An example would be and Escalating Appender that checks if a certain amount of identical Events get logged and if so logs the Event with a higher logleve. So you could define something like: If you get more th...

How do I create a new Joda DateTime truncated to the last hour?

I am pulling timestamps from a file that I want to create a new DateTime for, but I want to create the DateTime at the floor of the hour (or any Joda Period will do). How Can I do this? ...

Testing Java database entity classes

Currently we are testing out entity classes and "worker" classes by writing java servlets for each entity and doing Insert,update,delete,find... for each entity to ensure that it works. The worker classes are simply implementations of an interface that persists the entity to the database using JDBC, they do the DB work for the entity. W...

Optimal number of connections in connection pool

Currently we are using 4 cpu windows box with 8gb RAM with MySQL 5.x installed on same box. We are using Weblogic application server for our application. We are targeting for 200 concurrent users for our application (Obviously not for same module/screen). So what is optimal number of connections should we configured in connection pool (m...

When to recompile JNI bindings and client code?

Let's say I hav: a C library libfoo, a package org.foo.jni of JNI bindings to libfoo, and a package com.user.of.foo of client code. Obviously, if functions that org.foo.jni touches in libfoo change, I need to recompile the classes in org.foo.jni. And, also obviously, if methods that com.user.of.foo touches in org.foo.jni change, I n...

Using An Absolute Path With FreeMarker

I've been using FreeMarker for a little while now, but there's one glaring piece of functionality that is either missing or I just can't figure out (I hope the latter!). If you pass cfg.getTemplate() an absolute path, it just doesn't work. I know you can specify a template directory, but I can't afford to do that, my use case could dea...

What is the Cost of Calling array.length

While updating for loops to for-each loops in our application, I came across a lot of these "patterns": for (int i = 0, n = a.length; i < n; i++) { ... } instead of for (int i = 0; i < a.length; i++) { ... } I can see that you gain performance for collections because you don't need to call the size() method with each loop. ...

Do you use assertions?

This is not really a "question" so I'm making it CW. The assert Keyword is great! It should make, feel your self more confident with the code you wrote, but, until today when I was creating a small test class ( < 20 lines ) I realize a never use it since it was introduced. Heck! I barely use logger which is very useful indeed, ...

Using Prepared Statements to set Table Name

Im trying to use prepared statements to set a table name to select data from but i keep getting an error when i execute the query. The error and sample code is displayed below. [Microsoft][ODBC Microsoft Access Driver] Parameter 'Pa_RaM000' specified where a table name is required. private String query1 = "SELECT plantID, edrman, pl...

Action commands vs Action classes?!

A shout out to the Swing gurus out there!! I've been doing Swing programming for several years but have always been unclear on this. As you know Swing/AWT gives you several ways to execute a particular action when a button is clicked. I've seen it done several different ways in the applications I've worked on. The project I'm currentl...

Typically, what does it mean when java returns a "The parameter is incorrect"

I am creating a file like so try { File file = new File(workingDir, obj.getName() + ".xls"); outputStream = new FileOutputStream(file); } catch (FileNotFoundException ex) { ex.printStackTrace(); } And I am getting java.io.FileNotFoundException: ..\a\relative\path\obj_name.xls (The parameter is incorrect) at java.io....

displaying errors with custom component

While creating a Custom component that works like h:messages tag but in addition with that, if I click the messages, it focuses to each input fields from where the error occured. It works fine but the form gets empty. All the values get disappeared if any error occurs in the form. I was not able to figure out why? I am extending Rend...

Visualizing Data in Java

Hi, is there a good library on the market to visualize big datas in Java. Maybe a library for statistical outputs. I know the programming language R to visualize statistical data in R. I also have seen a solution to connect Java and R. It would be better if a have a pure Java solution. ...

Where methods live? Stack or in Heap?

Hi, I know that local variables and paramters of methods live in stack, but I not able to figure out where does actually methods live in case of Java? If I declare any Thread object like: Thread t=new Thread(); t.start(); So it means I've created a separate calling of methods apart from main method. What does it mean? Does it mean c...

FindBugs and Maven

I would like Maven to generate a FindBugs report where the bugs are grouped by severity, not by file. Then I would be able to focus on the most serious bugs immediately. I have seen similar functionality with the FindBugs plugin for Eclipse. Is this possible with Maven? ...

struts.xml cant find action or result

New to struts Here is the error: Jul 30 14:42:04 ERROR http-8080-Processor18 Dispatcher.serviceAction:512 - Could not find action or result No result defined for action com.domain.location.action.LocationAction and result input - action - file:/opt/apache-tomcat-5.5.20/webapps/location/WEB-INF/classes/struts.xml:1203:37 Here is my jsp...

Is it bad practice to include properties/configuaration files within jars?

For example: MyApp is a web app that contains a properties file (server.properties) that describes config data (e.g. server names) for the app. In the development phase, server.properties is located in its own IDE project folder (a logical spot for it). Now it's time to deploy MyApp. The IDE makes it quite trivial to jar up the class...

Java Problem running a .bat file

I'm trying to run two bat files from a Java app. I'm using: try { Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(fullCommand); InputStream stderr = proc.getErrorStream(); InputStreamReader isr = new InputStreamReader(stderr); BufferedReader br = new BufferedReader(isr); int exitVal = proc.waitFor(); System.out...