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

is EJBContext threadsafe?

 
John Peck
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I went through the EJB 3.2 spec, seems there is no explicit description about the thread safety of EJBContext. Anyone can help?
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Leon,
This is an old thread. If you have a problem, I would suggest to create a new topic for the same.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic