It's not a secret anymore!
The moose likes EJB and other Java EE Technologies and the fly likes @Resource UserTransaction utx; // thread safe? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "@Resource UserTransaction utx; // thread safe?" Watch "@Resource UserTransaction utx; // thread safe?" New topic

@Resource UserTransaction utx; // thread safe?

Jelo Nehuptra
Ranch Hand

Joined: Oct 08, 2011
Posts: 36

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

Joined: Jul 11, 2010
Posts: 247

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.

SCJP 6 [SCJP - Old is Gold]
Joemon Anthony

Joined: May 22, 2011
Posts: 26

Ram is absolutely correct. Session beans are for these things only. The container will take care of thread safety of the beans.

(SCJP 5, OCA 9i)
(Always interested in learning)
I agree. Here's the link:
subject: @Resource UserTransaction utx; // thread safe?
It's not a secret anymore!