This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

singleton class across  RSS feed

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,'
I have a singleton class which is referred in a jar file.Now the jar file is included in multiple ear file.Let's take an example.
I have singleton class which is present in a singleton.jar and this jar file is copied in 4 different ear/war file.Now my requirement is
this class has to be singleton across multiple appliation.But when iam instatiating across application(.ear) file then it creates a different
singleton class.Is there any otherway other than making these ear files referring to single jar file.
 
author and jackaroo
Marshal Commander
Posts: 12211
272
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This doesn't seem to be related to SCEA. Did you mean to post it in BEA/WebLogic? (just guessing based on some of your previous posts). I can move this if you provide a hint on where you would like it moved to.
 
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have these options

1. Move the jar up the class loader hierarchy so that it is loaded once.
2. Use an app server that uses a unified classloader factory. This way the first instance of the class will be picked up and the rest will be discarded.

Any reason why this Singleton is creating a problem across multiple apps ?
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your singleton getInstance() method synchronized??

Refer to Head First Design Patterns -pg 180 ...I think you will get your answer.

Ashish
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

srivastava ashish wrote:Is your singleton getInstance() method synchronized??

Refer to Head First Design Patterns -pg 180 ...I think you will get your answer.

Ashish



That will not solve the problem when the same class is loaded by different class loaders
 
srivastava ashish
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for pointing that out deepak..but is there any harm in putting singleton.jar in server classpath rather than individual EARs??. It might just work
 
no wonder he is so sad, he hasn't seen this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!