In reference to static methods and fields in an EJB:

Where are static methods prohibited?  In the EJB 1.0 spec, I don't
find any reference to static methods at all.  In the EJB 1.1 spec,
I find that certain bean methods can't be declared static:
   - ejbCreate (6.10.13, 9.2.3)
   - the [remote] business methods (6.10.14, 9.2.6)
   - ejbPostCreate (9.2.4)
   - ejbFind (9.2.5)
But I don't see any other prohibitions on static methods.  What am
I missing?

For static fields, the EJB 1.0 spec, section 16.4, says:

   "An enterprise Bean is not allowed to use read/write static fields.
    Using read-only static fields is allowed. Therefore, all static
    fields must be declared as final."

The EJB 1.1 spec, section 18.1.2, says:

   "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."

Note that the 1.1 spec relaxed the restriction.  Thinking about it,
my understanding is that the intent is to guarantee that a class
will contain the same static field values no matter where or when
it is loaded and statically initialized.  The same EJB class might
be loaded on different VMs for the purposes of load balancing or
fail over.  If the static field could receive a different value in
different VMs, the transparency across the cluster would be lost.
Based on my interpretation (which is barely worth the pixels it's
written with, I suppose ;-), I would say that the following is in
keeping with the spirit of the spec:

public class MyEJB implements SessionBean {

     private static int i;

     static {
         i = readProperty( );
     }
}

But *only if* readProperty( ) returns the same value each time the
class is loaded on different VMs.

Your mileage may vary...

Paul

===========================================================================
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