• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

static final variables in EJB

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 906
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Can you really tell me that we aren't dealing with suspicious baked goods? And then there is this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic