• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

singleton class across

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I have a knack for fixing things like this ... um ... sorry ... here is a consilitory tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic