aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes is EJBContext threadsafe? 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 "is EJBContext threadsafe?" Watch "is EJBContext threadsafe?" New topic
Author

is EJBContext threadsafe?

John Peck
Greenhorn

Joined: Jun 07, 2011
Posts: 3
Is EJBContext threadsafe?

Is following code correct/threadsafe (I like to inject PrincipalBean with CDI to JSF Beans)?



If I annotate above "getPrincipal()" with CDIs Produces annotation, is that correct (I mean threadsafe)?
Udara Amarasinghe
Ranch Hand

Joined: Aug 17, 2009
Posts: 109

Hi John,

First, you are welcome to the JavaRanch forum

And All the components in a server side managed environment are thread safe. Because in a managed environment we can't use multiple threads.
John Peck
Greenhorn

Joined: Jun 07, 2011
Posts: 3
I think I'd to clarify my question:

PrinciplaBean is a Singleton (see code above), so on a heavy load machine the method "getPrincipal()" can be called simultaneously by two or more users (=threads). Each thread uses the same "ejbContext" (because it's a private member in a sigleton) to call "getCallerPrincipal()".

Without the @ConcurrencyManagement(ConcurrencyManagementType.BEAN) annotation there will be a write lock on "getPrincipal()" and then there's no concurrency problem, but this will not scale on a heavy load machine. So I decided to remove the lock.

So my question: Is ejbContext.getCallerPrincipal() threadsafe (in the way, that one (single) instance of ejbContext is called simultaneously by two or more users? Or in other words does getCallerPrincipal() return the proper principal?

Thanks, John
Leon Omk
Ranch Hand

Joined: Aug 17, 2010
Posts: 75

I went through the EJB 3.2 spec, seems there is no explicit description about the thread safety of EJBContext. Anyone can help?


OK, so that other guy knows Java better than I do, but I bet he can't speak Wuhanese(a Chinese Dialect) like me.
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1083
    
  10

Hi Leon,
This is an old thread. If you have a problem, I would suggest to create a new topic for the same.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: is EJBContext threadsafe?