Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Synchronization  RSS feed

 
Roddy Georgieva
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am writing an application that has a servlet, which talks to an EJB, which talks to the database via a Data Access Object.
jsp <-> servlet <-> ejb <-> dao <-> database
I was wondering what would happen if I have the reference to the EJB declared as an instance variable of my servlet. (note: My servlet does NOT implement the SingleThreadModel interface.)
Since instance variables are not thread-safe, when the servlet doesn't implement the SingleThredModel interface and they are not synchronized later in the code, my question is "how safe is this"?
What will happen if several threads access this reference at the same time. Will the EJB container take care of any synchronization issues?
Thanks
 
Dave Landers
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on what kind of EJB you have. If it is a stateless session bean, then keeping the reference to the EJBObject (or EJBLocalObject) is probably OK as the container will handle routing each method call to a pooled instance of an implementation.
Although if something happens to the server (it goes dow and is replaced with a backup server, for example) you might need to rebuild your remote reference (like thru EJBHandle or something). Not sure - this depends on your deployment configuration.
If the bean is stateful (a stateful session bean or an entity) then you should not keep its reference around like this.
 
Roddy Georgieva
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using stateless EJBs, so I'll be safe having the remote interface as an instance variable in my servlet. I just wanted to make sure, I'm doing this right.
Thanks for your help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!