• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static final variables in EJB

 
Trevor Dunn
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 906
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic