Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threading in Containers

 
Meghna Bhardwaj
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI guys,

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

http://www.coderanch.com/t/320191/EJB-JEE/java/Threading-containers

Any responses will be much appreciated!
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic