Skip to content

Instantly share code, notes, and snippets.

@abhirockzz
Created September 13, 2014 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhirockzz/c161099358381775e87a to your computer and use it in GitHub Desktop.
Save abhirockzz/c161099358381775e87a to your computer and use it in GitHub Desktop.
Sticking with Container managed concurrency. Changing the explicit lock type from WRITE to READ
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.ConcurrencyManagement;
import javax.ejb.ConcurrencyManagementType;
import javax.ejb.Lock;
import javax.ejb.LockType;
import javax.ejb.Singleton;
import javax.ejb.Startup;
@Singleton
@Startup
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
public class MySingletonBean {
@Lock(LockType.READ)
public void act() {
System.out.println("Entered MySingletonBean/act() on " + new Date().toString() + " . Singleton instance " + this.hashCode() + " Thread : " + Thread.currentThread().getName());
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {
Logger.getLogger(MyStatefulBean.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("Exit MySingletonBean/act() on " + new Date().toString() + " . Singleton instance " + this.hashCode() + " Thread : " + Thread.currentThread().getName());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment