Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can I use Static Variable in Ejb class?  RSS feed

 
Parshuram Walunjkar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Can I use Static Variable in Ejb class?
Regards
From
Parshuram Walujkar
 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You can use the static final variable without problems in an EJB.
However if you use static variables which are not final then if you deploy your EJB in more than one application server the static variable may not be consistentent over the servers. If this is not a requirement then its ok I guess.
The ejb specification in fact contains a sample with static final variables
 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Please also note this section from the ejb spec

24.1.2 Programming restrictions
This section describes the programming restrictions that a Bean Provider must follow to ensure that the
enterprise bean is portable and can be deployed in any compliant EJB 2.0 Container. The restrictions
apply to the implementation of the business methods. Section 24.2, which describes the Container’s
view of these restrictions, defines the programming environment that all EJB Containers must provide.
• An enterprise Bean must not use read/write static fields. Using read-only static fields is
allowed. Therefore, it is recommended that all static fields in the enterprise bean class be
declared as final.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!