• 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
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!