• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

singleton class across

 
guru prasanth
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.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11914
209
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.
 
Deepak Bala
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 ?
 
srivastava ashish
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic