privateString process ="";publicObjectselectSingle(@PathVariableString accountID){String uuid =UUID.randomUUID().toString().replaceAll("-","");Thread.currentThread().setName(uuid.substring(0,10));String s1 =String.valueOf(Thread.currentThread().getName());for(int i =0; i <3; i++){if(process.equals("")){// 已获取到锁,进入处理
process = s1;// 上锁System.out.println("线程1的线程号为:"+ process);break;}else{if(!process.equals(s1)){// 锁已被获取,等待1秒后重新获取try{Thread.sleep(1000);}catch(InterruptedException e){
e.printStackTrace();}}else{// 锁已被获取,且获取锁的线程就是此线程,可以继续处理break;}}}if(!process.equals(s1)){// 3次机会用完,还没获取到锁,结束处理returnResponseEntity.status(500).body(newReturnVo("Failure","400","The Data is currently in use, please wait a minute with try again"));}// 开始处理主要业务// 。。。。。。处理中。。。。。。。。。// 处理完毕,释放锁
process ="";}publicObjectselectAll(@PathVariableString accountID){String uuid =UUID.randomUUID().toString().replaceAll("-","");Thread.currentThread().setName(uuid.substring(0,10));String s1 =String.valueOf(Thread.currentThread().getName());for(int i =0; i <3; i++){if(process.equals("")){// 已获取到锁,进入处理
process = s1;// 上锁System.out.println("线程2的线程号为:"+ process);break;}else{if(!process.equals(s1)){// 锁已被获取,等待1秒后重新获取try{Thread.sleep(1000);}catch(InterruptedException e){
e.printStackTrace();}}else{// 锁已被获取,且获取锁的线程就是此线程,可以继续处理break;}}}if(!process.equals(s1)){// 3次机会用完,还没获取到锁,结束处理returnResponseEntity.status(500).body(newReturnVo("Failure","400","The Data is currently in use, please wait a minute with try again"));}// 开始处理主要业务// 。。。。。。处理中。。。。。。。。。// 处理完毕,释放锁
process ="";}