views:

80

answers:

1

I'm using some legacy java code that consists of several static classes from with in a Grails app under tomcat. When I only have one user using the web application everything works fine. When two users use the application things start to go wrong. I believe it's because the static classes maintain resource locks such as sockets. Am I correct in assuming that by default all sessions in the application will use the same copy of the static class? If so is there a way to change this behavior to load a new copy for each user session?

A: 

No there isn't away to map static methods to http sessions in tomcat or any other application server. Having said that static methods are only a problem if they are holding state statically.

If this is the case then you will either need to rewrite those classes such that you can hold instances in the Session.

Gareth Davis
They hold state for a short time, it looks like putting synchronize around any calls to them fixes the problem.
Jared
You might be able to modify the class definitions so that methods have the synchronized keyword in the method defintion. public synchronized methodName() { }That way you don't have to worry about wrapping it in a synchronized block at each method invocation.
Sean A.O. Harney