- 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.
推薦閱讀
- .NET之美:.NET關(guān)鍵技術(shù)深入解析
- Kibana Essentials
- 數(shù)據(jù)結(jié)構(gòu)(Java語(yǔ)言描述)
- MariaDB High Performance
- 零基礎(chǔ)學(xué)Python數(shù)據(jù)分析(升級(jí)版)
- SharePoint Development with the SharePoint Framework
- JavaScript+jQuery網(wǎng)頁(yè)特效設(shè)計(jì)任務(wù)驅(qū)動(dòng)教程
- App Inventor 2 Essentials
- Appcelerator Titanium:Patterns and Best Practices
- Python面試通關(guān)寶典
- 3D Printing Designs:The Sun Puzzle
- Data Manipulation with R(Second Edition)
- Kotlin入門與實(shí)戰(zhàn)
- Clojure High Performance Programming
- 微軟辦公軟件認(rèn)證考試MOS Access 2013實(shí)訓(xùn)教程