Static variable in session bean

Can we declare static variable in session bean. If we declare what will happen. Will it create error in compile time or not deployed in server.
[157 byte] By [sgbalakumara] at [2007-11-26 19:02:08]
# 1

From a Java language perspective, nothing stops you from declaring a static variable in a session

bean class.It will compile as long as its syntactically correct.

From an EJB programming model perspective, the use of *non-final* static variables

is discouraged because it breaks the JVM-transparency that is an important aspect of the

EJB architecture.It should be possible to deploy a single EJB application to a cluster and

have it behave exactly as if it were deployed to only one server instance (albeit with higher

overall throughput/performance).Using non-final static variables breaks this property

because the bean instances in one JVM will see a different value for the static variable

than bean instances in a different JVM.

It also forces you to deal with synchronization

of the shared data, which is a complexity that was carefully avoided in the EJB programming

model by ensuring that each bean instance is single-threaded.

Bottom line is you can have "final static" data members in EJB classes but you should

avoid non-final (mutable) static data.

--ken

ksaksa at 2007-7-9 20:47:34 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...