java

How to synchronize requests for data with data update process?

I have an application that uses a cron like job to update a set of data. The update process happens once a minute and doesn't last long. A servlet exposes this data set to the users. My problem is that during the update process, the servlet requests should block and wait for the process to complete. In bottom line I have these two func...

Java listener must inherit from java.util.EventListener - why?

In the javadoc it says that EventListener is "A tagging interface that all event listener interfaces must extend." Why is that? What's the significance of making a custom listener implement EventListner? Is there any special handling for EventListner somewhere? ...

Shortest way to get an Iterator over a range of Integers in Java

What's the shortest way to get an Iterator over a range of Integers in Java? In other words, implement the following: /** * Returns an Iterator over the integers from first to first+count. */ Iterator<Integer> iterator(Integer first, Integer count); Something like (first..first+count).iterator() ...

Securing ActiveMQ externally by IP filtering

I have an instance of ActiveMQ running on an externally facing server and exposing a STOMP interface. I would like to be able to ensure that externally connected clients can only receive topic notifications, and not send anything to the topic themselves. Any internally connected clients will be able to both receive and send. I was hop...

Analyze Tomcat Heap in detail on a production System

Having analyzed a light-load web application running in tomcat, using JMX Console, it turns out the "PS Old Gen" is growing slowly but constant. It starts with 200MB and grows around 80MB/Hour. CPU is not an issue, it runs at 0-1% on average, but somewhere it leaks memory, so it will become unstable some days after deployment. How do i...

Any Good ORM tools for Android development?

Anyone working on the Android ('gPhone') have or know of a place where I can find a good ORM tool for it? The code is written in Java, and the DB is SQLite. What I would like to find is a tool that given the object definition, can auto-generate the tables and the CRUD functions (that would be awesome), or, barring that, a tool that can...

How to tell Java which StringEscapeUtils.escapeXML() to use???

I'm trying to use the StringEscapeUtils.escapeXML() function from org.apache.commons.lang... There are two versions of that function, one which expects (Writer, String) and one which just expects (String).... http://commons.apache.org/lang/api/org/apache/commons/lang/StringEscapeUtils.html#escapeXml(java.lang.String) I'm trying to use...

Java JAXB Pros/Cons and Documentation

It's been a while since I used Java in anger so please forgive me if this is silly. I have just got started on a Java project where we are using JAXB to de-serializing an incoming XML string (from Jetty Server). The project is only using JAXB for this situation. What are the alternatives to JAXB? What are pros/cons of JAXB to these alt...

Java Mobile programming for a beginner, where to start?

After I downloaded the Google Mail and Google Maps application into my mobile phone I got an idea about a service that I want to implement. My problem is that I never did any programming for the mobile platform and I need someone to point me out some resources for the Hello World on a mobile and then something a bit more complicated. L...

Java nested list to array conversion

What is the most efficient way to convert data from nested lists to an object array (which can be used i.e. as data for JTable)? List<List> table = new ArrayList<List>(); for (DATAROW rowData : entries) { List<String> row = new ArrayList<String>(); for (String col : rowData.getDataColumn()) row.add(col); table.add...

Why do you subdivide into maven-modules for in-house projects ?

We have this constant discussion in our project as to the granularity of our maven modules. We have come to agree that there may be differences in the needs of a framework (like spring) and an in-house application that is always deployed monolithically. We also agree that it's fairly sensible to hide implementation details of adapters t...

Regex to find an integer within a string

I'm new to using regex and I'd like to use it with Java. What I want to do is find the first integer in a string. Example: String = "the 14 dogs ate 12 bones" Would return 14. String = "djakld;asjl14ajdka;sdj" Would also return 14. This is what I have so far. Pattern intsOnly = Pattern.compile("\\d*"); Matcher makeMatch = intsOnly....

Java: Generics, arrays, and the ClassCastException

I think there must be something subtle going on here that I don't know about. Consider the following: public class Foo<T> { private T[] a = (T[]) new Object[5]; public Foo() { // Add some elements to a } public T[] getA() { return a; } } Suppose that your main method contains the following: Foo<Double> f = new Foo...

Java passphrase encryption

I'm trying to learn how to do passphrase-based encryption with Java. I'm finding several examples online, but none (yet) on Stack Overflow. The examples are a little light on explanation for me, particularly regarding algorithm selection. There seems to be a lot of passing strings around to say what algorithms to use, but little docum...

Where do Java and .NET string literals reside?

A recent question about string literals in .NET caught my eye. I know that string literals are interned so that different strings with the same value refer to the same object. I also know that a string can be interned at runtime: string now = DateTime.Now.ToString().Intern(); Obviously a string that is interned at runtime resides on t...

Automated Exception Handling

I was wondering if something exists (in Java world) able to take an snapshot of the JVM current state with the following features: Do it while an exception is being thrown. Capture local variables, method's arguments, etc. Put it in a handy file which can be used to extract or reproduce in a IDE the situation in your source code. The...

Pattern suggestions needed (Hibernate + Guice)

Hi, all, I'm looking for suggestions on how to inject runtime dependencies into JPA entities retrieved from Hibernate. My problem is essentially this: I have a number of different subclasses of a Transaction object. Each Transaction subclass has different behavior when it is executed, and requires a different set of dependencies from t...

Dynamically loading a class file with a non default package and no nested folders

I am writing a curriculum project for students new to Java. It has a folder structure as so. myjar.jar solutions/my/really/long/package/MySolution.class I got it so the jar can load all classes in the solutions/my/really/long/package/ directory. by adding 'solutions/' to the classpath. My question is if it is possible to set it up so...

Does anyone know of any good tutorials for the Slick 2D lib?

There is a 2D java graphics library called Slick 2D (http://slick.cokeandcode.com/) that seems to be used by a bunch of indie games (mostly applets), but the documentation is a little lacking. Does anyone know of any good tutorials for this lib? ...

org.jgroups.protocols.UDP - failed sending message to null

[hannel,192.168.0.46:40014] 15:08:03,642 - ERROR - org.jgroups.protocols.UDP - failed sending message to null (61 bytes) java.lang.Exception: dest=/225.1.2.46:30446 (64 bytes) at org.jgroups.protocols.UDP._send(UDP.java:333) at org.jgroups.protocols.UDP.sendToAllMembers(UDP.java:283) at org.jgroups.protocols.TP.doSend(TP.java...