- Jakarta EE Cookbook
- Elder Moraes
- 126字
- 2021-06-24 16:12:47
How to do it...
This recipe will take you through three scenarios. Let's get started:
- 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++;
}
}
- 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++;
}
}
- 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.
推薦閱讀
- Mastering Concurrency in Go
- Xcode 7 Essentials(Second Edition)
- 跟小海龜學Python
- OpenCV 3和Qt5計算機視覺應用開發
- Java Web基礎與實例教程
- Learning Network Forensics
- Elasticsearch for Hadoop
- Oracle GoldenGate 12c Implementer's Guide
- Learning Material Design
- SQL Server 2008 R2數據庫技術及應用(第3版)
- Django 5企業級Web應用開發實戰(視頻教學版)
- Bootstrap for Rails
- 硬件產品設計與開發:從原型到交付
- Visual Basic 程序設計實踐教程
- 超好玩的Scratch 3.5少兒編程