• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Does transaction isolation applies on static variables ?

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 45
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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;
}
}



 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic