官术网_书友最值得收藏!

How to do it...

This recipe will take you through three scenarios. Let's get started:

  1. In the first scenario, LockType is defined at the class level:
@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
@Lock(LockType.READ)
@AccessTimeout(value = 10000)
public class UserClassLevelBean {

private int userCount;

public int getUserCount() {
return userCount;
}

public void addUser(){
userCount++;
}

}
  1. In the second scenario, LockType is defined at the method level:
@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
@AccessTimeout(value = 10000)
public class UserMethodLevelBean {

private int userCount;

@Lock(LockType.READ)
public int getUserCount(){
return userCount;
}

@Lock(LockType.WRITE)
public void addUser(){
userCount++;
}
}
  1. The third scenario is a self-managed bean:
@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
public class UserSelfManagedBean {

private int userCount;

public int getUserCount() {
return userCount;
}

public synchronized void addUser(){
userCount++;
}
}

Now, let's see how this recipe works.

主站蜘蛛池模板: 文昌市| 尉犁县| 台江县| 高州市| 大足县| 获嘉县| 克东县| 正阳县| 郎溪县| 洪泽县| 锡林浩特市| 黎川县| 岳阳县| 梁河县| 衡南县| 乌拉特前旗| 河东区| 屏南县| 兴隆县| 天门市| 英超| 谷城县| 白河县| 集贤县| 黄梅县| 金阳县| 寿宁县| 雷州市| 舞阳县| 廊坊市| 佳木斯市| 潼关县| 开原市| 杨浦区| 神池县| 西城区| 白银市| 油尖旺区| 黄大仙区| 中方县| 寿光市|