wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes static final variables in EJB 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 final variables in EJB" Watch "static final variables in EJB" New topic
Author

static final variables in EJB

Trevor Dunn
Ranch Hand

Joined: Jun 13, 2001
Posts: 84
Hello,
I had read somewhere that static variables are frowned upon in an EJB but static final is ok. Could someone explain this to me.
I am using log4j and using static final Category category in my EJB and all seems fine.But I do not know why
Trevor
JeanLouis Marechaux
Ranch Hand

Joined: Nov 12, 2001
Posts: 906
I'll try to answer to your question.
The value of a static variable is maintained within the current JVM.
But an EJB can be accessed by a different JVM for each client.
So a static variable in an EJB is not really shared.
If an EJB modify the value of the variable, only EJBs within the same JVM will see the change.
So the code is not safe.
Actually, I don't think the EJB spec prevent you from using STATIC variables. I've never perform the test.
It just advises not to use them.

HTH.


/ JeanLouis<br /><i>"software development has been, is, and will remain fundamentally hard" (Grady Booch)</i><br /> <br />Take a look at <a href="http://www.epfwiki.net/wikis/openup/" target="_blank" rel="nofollow">Agile OpenUP</a> in the Eclipse community
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
static final variables are those whose values are completely fixed at compile time. Therefore, no matter which JVM (in a cluster) you are using, you'll always get an equivalent value for the variable.
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: static final variables in EJB