Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

EJB%20Interview%20Questions%20and%20Answers

Question: Static variables in EJB should not be relied upon as they may break in clusters.Why?
Answer: Static variables are only ok if they are final. If they are not final, they will break the cluster. What that means is that if you cluster your application server (spread it across several machines) each part of the cluster will run in its own JVM.

Say a method on the EJB is invoked on cluster 1 (we will have two clusters - 1 and 2) that causes value of the static variable to be increased to 101. On the subsequent call to the same EJB from the same client, a cluster 2 may be invoked to handle the request. A value of the static variable in cluster 2 is still 100 because it was not increased yet and therefore your application ceases to be consistent. Therefore, static non-final variables are strongly discouraged in EJBs.
Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook