Lock&Condition
amp lock condition
2023-09-14 08:57:28 时间
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class ThreeConditionCommunication {
* @param args
public static void main(String[] args) {
final Business business = new Business();
new Thread(
new Runnable() {
@Override
public void run() {
for(int i=1;i =50;i++){
business.sub2(i);
).start();
new Thread(
new Runnable() {
@Override
public void run() {
for(int i=1;i =50;i++){
business.sub3(i);
).start();
for(int i=1;i =50;i++){
business.main(i);
static class Business {
Lock lock = new ReentrantLock();
Condition condition1 = lock.newCondition();
Condition condition2 = lock.newCondition();
Condition condition3 = lock.newCondition();
private int shouldSub = 1;
public void sub2(int i){
lock.lock();
try{
while(shouldSub != 2){
try {
condition2.await();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
for(int j=1;j =10;j++){
System.out.println("sub2 thread sequence of " + j + ",loop of " + i);
shouldSub = 3;
condition3.signal();
}finally{
lock.unlock();
public void sub3(int i){
lock.lock();
try{
while(shouldSub != 3){
try {
condition3.await();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
for(int j=1;j =20;j++){
System.out.println("sub3 thread sequence of " + j + ",loop of " + i);
shouldSub = 1;
condition1.signal();
}finally{
lock.unlock();
public void main(int i){
lock.lock();
try{
while(shouldSub != 1){
try {
condition1.await();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
for(int j=1;j =100;j++){
System.out.println("main thread sequence of " + j + ",loop of " + i);
shouldSub = 2;
condition2.signal();
}finally{
lock.unlock();
}
1120 11g select for update skip locked [20171120]11g select for update skip locked.txt --//11G在select for update遇到阻塞时可以通过skipped locked跳过阻塞的记录,测试看看: 1.
1120 11g select for update skip locked [20171120]11g select for update skip locked.txt --//11G在select for update遇到阻塞时可以通过skipped locked跳过阻塞的记录,测试看看: 1.
相关文章
- NoSQL高级培训课程-HBase&&MongoDB(两天版)
- [Angular] AfterContentChecked && AfterViewChecked
- [Grunt] grunt.initConfig() && grunt.file
- js中的|| 和 &&
- 无法打开物理文件 "D:understructuredata _DAT.MDF"。操作系统错误 5:"5(拒绝访问。)"
- PLSQL连Oracle数据库Could not load "……binoci.dll"
- 华为OD机试 - 找出经过特定点的路径长度(Java & JS & Python)
- 华为OD机试 - 火星文计算(Java & JS & Python)
- error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/
- ML之LiR&2PolyR&4PolyR:使用线性回归LiR、二次多项式回归2PolyR、四次多项式回归4PolyR模型在披萨数据集上拟合(train)、价格回归预测(test)
- Go 接口嵌套组合的使用方法 & gomock 测试 stub 代码生成
- n&(n-1)的用途