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

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.

主站蜘蛛池模板: 辽阳县| 军事| 虹口区| 大化| 长汀县| 朝阳县| 河津市| 抚顺县| 丹巴县| 桐柏县| 岚皋县| 应城市| 潜江市| 浦县| 绥芬河市| 安图县| 遂昌县| 进贤县| 花垣县| 托里县| 沙田区| 西城区| 新民市| 宁波市| 三门县| 栾川县| 桑日县| 郁南县| 吴川市| 东山县| 抚松县| 宣化县| 和平县| 太仆寺旗| 博白县| 钟山县| 古浪县| 论坛| 遂平县| 新竹市| 扶风县|