Hi!

Ron Yust wrote:
> Does the spec mean no static methods/data in the EJB bean only or no static
> items in ANY other java class the bean accesses?  For example, could a
> session bean access a static variable in a class outside the bean?

Instead of looking at the symptoms, let me explain the problem.

Why can't we have statics?

Two reasons (mainly):
* Your application might be in a cluster, so having statics in a bean
does not necessarily mean it's a singleton. If your bean is deployed to
several servers in a cluster this will not be the case
* Your bean JAR will most likely be loaded with a customized
classloader, to be able to easily add security restrictions, and to be
able to redeploy easily. The last point is the killer here: when an EJB
server wants to redeploy your beans, the easiest implementation of this
is to simply dump the classloader (and all the classes in it), and
construct a new one pointing at your JAR. This means that any statically
modified fields in classes will effectively be reset.

Using this knowledge you should be able to extrapolate to what cases are
covered, and which are not. Binding a RMI-object in JNDI is the best
solution at getting singletonbehaviour that I know of, because it wont
get reloaded, and (a bit depending on implementation of JNDI in the
server) you should get transparent access to it in clusters.

Then again, with the above knowledge you can assume that if you do not
use clusters, and you never redeploy your bean, you should be fine using
statics :-) But then again, you might not want to *depend* on that if
you want to upscale your app later on. ;-)

I hope this made sense :-)

/Rickard

--
Rickard �berg

@home: +46 13 177937
Email: [EMAIL PROTECTED]
Homepage: http://www-und.ida.liu.se/~ricob684

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to