We are currently writing a system which parses data into PDF output via Apaches FOP. This is done in a Servlet which needs to load data into variables and whoses process takes a reasonable amount of time i.e 5-10 seconds. This data is accessed by many of the methods used in the servlet.
The system can be used concurrently by many users.
Currently to preserve threadsafety a local instance container object (holding the data) is created and passed down into the various methods.
This can be a bit of a pain and I was looking at alternatives.
Is putting the container into a ThreadLocal class a viable alternative, it seems so IBM Example but then I've also seen article about crummy performance and also multiple threads per request???
Is there any other approach out there, apart from SingleThreadModel or synchronization. Effectively I want to access data specific to a request without the overhead of passing local variables all over the place?
Joined: Jan 29, 2003
Your servlet can do something as simple as this:
WorkerObject has no thread issues because you make a whole new one for every thread. You may decide you have object creation and GC issues instead, but you've already explored the alternative of all local variables and parameters so you can compare the pain and benefits.
This is more or less what Struts and other front controller designs do when they pass work off to action classes and such. Unless they use singleton action classes that have all the same thread issues as the darned servlet. :roll: [ December 13, 2004: Message edited by: Stan James ]
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Sep 22, 2003
Why didn't I think of that simple yet ideal for what I'm doing. I'm off to refactor now!