wood burning stoves*
The moose likes EJB and other Java EE Technologies and the fly likes Does transaction isolation applies on static variables ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Does transaction isolation applies on static variables ? " Watch "Does transaction isolation applies on static variables ? " New topic
Author

Does transaction isolation applies on static variables ?

Amr k. Saleh
Ranch Hand

Joined: Aug 23, 2010
Posts: 41
Hi All,

it might be a dummy question, does transaction isolation applies on static variables? i mean does EJB container manages locking static variable if used in a transaction ?

thanks in advance
s patnaik
Ranch Hand

Joined: Jul 17, 2011
Posts: 45

I am not sure if I understand your question correctly.

What I can say is that the EJB container only makes sure that a bean instance is associated with only one thread at a time.

A static field can still be accessible across all threads. So thread A (associated with EJB instance A) can start a transaction and access and modify the static field. Simultaneously thread B (associated with EJB instance B) can start another transaction and access and modify the same static field at the same time.

Hope that helps !


SCJP 5, OCPJP7, OCMJEA 5
venk somis
Greenhorn

Joined: Jul 02, 2012
Posts: 2

May not understand your question properly, why someone wants to use a Static variable in Ejb ? You want have that in Stateless bean ? What is the purpose , One of the very important features that EJB-Container

provided is Thread-safety. So if you use Static in your EJBs, those are not Thread Safe.

One more thing, if you are looking for having some Singleton Classes in EJB layer, you can have that with latest EJB 3.1


The following bean load data in init() method and saves the data when destroyed

@Singleton
public class YourTestBean {
@PersistenceContext
private EntityManager entityManager;
private Rate rate;
@PostConstruct
private void init() {
rate = entityManager.find(Rate.class, 1);
}
@PreDestroy
private void destroy() {
entityManager.merge(rate);
}
public void setRate(Rate rate) {
this.rate = rate;
}
public Rate getRate() {
return rate;
}
}



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Does transaction isolation applies on static variables ?
 
Similar Threads
Isloation in the ACID rule?
two transactions under the same XA cordinator to the same resource
JDBC Isolation level?
does EJB2.0 supports transaction isolation levels?
Why does this give a stackoverflowerror?