aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes static classes in App Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "static classes in App Server" Watch "static classes in App Server" New topic
Author

static classes in App Server

Ankur Goyal
Greenhorn

Joined: Feb 04, 2002
Posts: 13
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 !!!


Let me know if I am wrong ! <img src="smile.gif" border="0">
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16137
    
  21

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).


Customer surveys are for companies who didn't pay proper attention to begin with.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
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.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static classes in App Server