Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@Resource UserTransaction utx; // thread safe?

 
Jelo Nehuptra
Ranch Hand
Posts: 36
Java jQuery Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I inject



in a Servlet and perform some



or even an update



am I assured that when 2 clients are running the same code, that the code within the UserTransaction is thread safe?
or I have to



???
 
Ram Narayan.M
Ranch Hand
Posts: 247
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each thread gets its own Transaction context and so is not thread safe.

And moreover, This kind of Data Persistence Logic can be put in Session bean which assures thread safe instead of Servlets.

Synchronizing in Servlet level, would slow down the Servlet container processing the requests.
 
Joemon Anthony
Greenhorn
Posts: 26
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ram is absolutely correct. Session beans are for these things only. The container will take care of thread safety of the beans.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic