File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes Threading in Containers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Threading in Containers" Watch "Threading in Containers" New topic

Threading in Containers

Meghna Bhardwaj
Ranch Hand

Joined: Jun 08, 2007
Posts: 109
HI guys,

I have some thread safety concerns about EJB, JSP, servlets in their respective containers. I mistakenly posted it at the below forum:

Any responses will be much appreciated!
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
From the other thread, that probably oughtta be closed ...

Yes, I am concerned about thread-safety as provided by the container, and when does the developer need to create threads themselves and take care of threading.

So is it correct to say that EJBs should be coded for a single thread and the container will manage/create multiple threads as required?

The 2nd paragraph is right on - the container does a lot of nifty stuff with threads, so the answer to the 1st paragraph is we should not do anything with threads. The container wants to manage threads entirely and if we go about creating them and locking them it can't do its job as well. The EJB spec and maybe the Servlet spec (I'd have to look on that one) tell you not to create threads.

Because that's rather restrictive, some container vendors have added some non-standard way to work with threads. I remember reading up on one in WebSphere but never used it. JMS queuing is another standard way to spawn an asynchronous task.

I've broken the rules in the past with a limited amount of very carefully controlled thread work, and gotten away with it so far.

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
I agree. Here's the link:
subject: Threading in Containers
jQuery in Action, 3rd edition