• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

static final variables initilization in EJBs

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,
Does any one know a better solution to assign the values to static final variables in EJBs (Entity Beans and also Session Beans). We have a need to initilize some of the static final variables in each of the CMP and that has to be read from a resource such as a config file bundled with in the jar file. I tried initilize the final values with in the static block of code in EJB's but while the EJBs are getting deployed to the Container ( Oracle 9iAS OC4J container ) it throws an Exception such as resource not found Exception !!!
If I do the same thing with in a static block of code in other plan class (not the EJB's) they work fine and all the static final variables are initilized !!!
But I want the static final variables to be part of EJB's and initilize them when the class is getting loaded!!! becasue I don't want to use one more plan class just to hold my final variable values
Any help is appreciated very much
Thank you
Mallik
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Mallik HM",
I'm afraid I have to ask you to change your display name as our naming policy does not allow initials for last name.
Thanks.
 
Mallik Hiremath
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does any one has a solution for this??
-Mallik
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you'll find that the EJB spec tells you you're not allowed to use statics, for precisely this kind of reason. Anything that multiple beans need to talk to should be located via JCA or JNDI or similar.
 
Mallik Hiremath
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The specification also says that you can use static final variables... so thought make use of this for some of the Preferences to set up. It looks like the loading of the ejb classes is not in our hands (as they get compiled to a different wrapper classes and then they are loaded ). If some one has solved the similare problem please let me know.
I can make use of the env-entry variables, but that leads to JNDI lookups and I still think just the static final variables are good for this.
-- Mallik
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mikal, I think the problem is the static initialization block. Clearly you can define a static final String inside an EJB. Nothing wrong with that. Trying to initialize it at class load time is the problem.
Try the alternative approach of putting final static strings that need initialization in the JNDI env namespace and do a lookup on them. Pretty much anytime you might think of something as a singleton or a static in EJB land it really belongs as a JNDI lookup.
dt
 
Mallik Hiremath
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Danl,
Do you or some one know the best method of populated the JNDI env namespace? or suggest some pointers?
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mallik Hiremath:
Thank you Danl,
Do you or some one know the best method of populated the JNDI env namespace? or suggest some pointers?


I think Danl might have referred to the "private JNDI namespace", which is populated based on your deployment descriptor.
For example, instead of having private static final String MY_CONSTANT = "foo", you'd have

and
 
Mallik Hiremath
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Lasse,
Yes, I know the env-entry tag, but every time I have to compare with some thing I need to lookup the JNDI, does any one is this an expensive statment?
Does any know how to specify constants that is applicable to all the EJBs in the application?
Thank you
Mallik
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, the JNDI lookup is expensive compared to a static final but as the variable is read-only, you only need to look it up once at bean creation time etc.
Btw, sorry about not reading the thread thoroughly. I just realized that the env-entry was already out there...
 
And when my army is complete, I will rule the world! But, for now, I'm going to be happy with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic