File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static classes in App Server

 
Ankur Goyal
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read this somewhere...
"There is a general advice from wise people that we should not use static classes because the classes are static within a class loader whereas an application server may have more than 1 class loader within the same JVM."
Would someone explain this !!!
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17616
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't think offhand why particularly "static" classes are an issue - for one thing, I'm not sure what that means - but I can personally testify that web appservers can bite you because they may use different classpaths internally.
If you actually have classes coming from more than one VM, you need something like RMI to communicate between them.
Just on the chance that the message got garbled coming from the "experts" and since this forum covers EJBs, I would mention that static members of an EJB should be avoided unless they are invariant (final).
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tim Holloway:
Just on the chance that the message got garbled coming from the "experts" and since this forum covers EJBs, I would mention that static members of an EJB should be avoided unless they are invariant (final).

And the reason is that if a class with a static member is loaded by more than one class loader, then changes to one static member will not be reflected in the other static member. In other words, there are no guarantees that static variables will be shared across all instances of a class.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic