Java Reference
In-Depth Information
Java EE offers two types of concurrency management: container‐managed concurrency and
bean‐managed concurrency . In container‐managed concurrency, the container is responsible for
handling anything related to read and write access, whereas bean‐managed concurrency expects
the developer to handle concurrency using traditional Java methods such as synchronization. You
can enable bean‐managed concurrency via the ConcurrencyManagementType.BEAN annotation.
Java EE uses container‐managed concurrency by default, but you can explicitly declare it with the
ConcurrencyManagementType.CONTAINER annotation:
public class CacheSingletonBean {
// Implementation code here.
Now you'll get back to the example and use the @Lock annotations to control the access. See Listing 4‐11.
LISTING 4‐11: Managing concurrency using @locktype
package com.devchronicles.singleton;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.ejb.ConcurrencyManagement;
import javax.ejb.ConcurrencyManagementType;
import javax.ejb.DependsOn;
import javax.ejb.EJB;
import javax.ejb.Lock;
import javax.ejb.LockType;
import javax.ejb.Singleton;
import javax.ejb.Startup;
public class CacheSingletonBean {
private Map<Integer, String> myCache;
MyLoggingBean loggingBean;
public void start(){
myCache = new HashMap<Integer, String>();
Search WWH ::

Custom Search