This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Reply 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: 14485
    
    7

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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: static classes in App Server
 
Similar Threads
Two war files in a single ear file and each war files has a static variable
Does this help prevent writing to a common file at the same time ?
how to hot deploy jar files
Help please...jar problem
Problem loading Properties file