This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About ServiceLocator

 
Anderson Fonseca
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I�ve been studying JPetstore1.3 i have noticed 2 ServiceLocator in project: one in ejb folder and another in web folder. But i be confuse why ejb/SL a don�t use a Singleton pattern?
 
vu lee
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is what I think. Consider the cost of synchronization--the cost of performing an synchronized operation is 100 times slower that the one that does not need to synchronize. According to the InitialContext's API,
An InitialContext instance is not synchronized against concurrent access by multiple threads. Multiple threads each manipulating a different InitialContext instance need not synchronize. Threads that need to access a single InitialContext instance concurrently should synchronize amongst themselves and provide the necessary locking.
Since web tier ServiceLocator uses singleton, a single InitialContext instance is concurrently accessed by multiple threads. Being in the same box with other ejb beans, EJB tier Servicelocator doesn't use singleton to avoid synchronization. Please, comment?
 
Anderson Fonseca
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree you about synch, however i think ejb/ServiceLocator with another name would be fit. Cause SL j2ee pattern display an implementation in a different form, ejb/SL could be a bit confuse.

thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic