81,091
社区成员
发帖
与我相关
我的任务
分享
@Override
public Map kill() {
ReentrantLock lock = new ReentrantLock();
Transaction tx =null;
Jedis jedis =null;
Map resultMap = new HashMap();
try {
lock.lock();
System.out.println("thread name : "+Thread.currentThread().getName() +" work ");
jedis = RedisApi.getResource();
Good skGood = (Good)RedisApi.get(CommonDefinition.SEC_KILL_GOOD.getBytes());
int secQuantity = skGood.getSecQuantity();
if(secQuantity<=0){
resultMap.put("scuess", false);
}else{
tx = jedis.multi();
skGood.setSecQuantity(secQuantity-1);
RedisApi.set(CommonDefinition.SEC_KILL_GOOD, skGood);
tx.exec();
resultMap.put("scuess", true);
resultMap.put("kill_good_num", secQuantity);
}
//System.out.println(resultMap.get("kill_good_num")+"/ "+lock.getHoldCount()+" / "+lock.toString());
return resultMap;
} catch (Exception e) {
e.printStackTrace();
if(null!=tx){
tx.discard();
}
RedisApi.returnBrokenResource(jedis);
}finally{
RedisApi.returnResource(jedis);
lock.unlock();
System.out.println("thread name : "+Thread.currentThread().getName() +" finished ");
}
return null;
}
thread name : http-bio-8080-exec-5 work
thread name : http-bio-8080-exec-5 finished
thread name : http-bio-8080-exec-7 work
thread name : http-bio-8080-exec-7 finished
thread name : http-bio-8080-exec-6 work
thread name : http-bio-8080-exec-6 finished
thread name : http-bio-8080-exec-3 work
thread name : http-bio-8080-exec-3 finished
thread name : http-bio-8080-exec-4 work
thread name : http-bio-8080-exec-4 finished
thread name : http-bio-8080-exec-9 work
thread name : http-bio-8080-exec-9 finished
thread name : http-bio-8080-exec-8 work
thread name : http-bio-8080-exec-8 finished
thread name : http-bio-8080-exec-10 work
thread name : http-bio-8080-exec-10 finished
thread name : http-bio-8080-exec-11 work
thread name : http-bio-8080-exec-11 finished
thread name : http-bio-8080-exec-12 work
thread name : http-bio-8080-exec-12 finished
thread name : http-bio-8080-exec-13 work
thread name : http-bio-8080-exec-13 finished
thread name : http-bio-8080-exec-14 work
thread name : http-bio-8080-exec-14 finished
thread name : http-bio-8080-exec-15 work
thread name : http-bio-8080-exec-15 finished
thread name : http-bio-8080-exec-16 work
thread name : http-bio-8080-exec-16 finished
thread name : http-bio-8080-exec-17 work
thread name : http-bio-8080-exec-17 finished
thread name : http-bio-8080-exec-19 work
thread name : http-bio-8080-exec-19 finished
thread name : http-bio-8080-exec-18 work
thread name : http-bio-8080-exec-18 finished
thread name : http-bio-8080-exec-20 work
thread name : http-bio-8080-exec-20 finished
thread name : http-bio-8080-exec-32 work
thread name : http-bio-8080-exec-32 finished
thread name : http-bio-8080-exec-8 work
thread name : http-bio-8080-exec-8 finished
thread name : http-bio-8080-exec-6 work
thread name : http-bio-8080-exec-6 finished
thread name : http-bio-8080-exec-4 work
thread name : http-bio-8080-exec-4 finished
thread name : http-bio-8080-exec-5 work
thread name : http-bio-8080-exec-5 finished
thread name : http-bio-8080-exec-19 work
thread name : http-bio-8080-exec-19 finished
thread name : http-bio-8080-exec-9 work
thread name : http-bio-8080-exec-9 finished
thread name : http-bio-8080-exec-5 work
thread name : http-bio-8080-exec-5 finished
thread name : http-bio-8080-exec-31 work
thread name : http-bio-8080-exec-31 finished
thread name : http-bio-8080-exec-3 work
thread name : http-bio-8080-exec-3 finished
thread name : http-bio-8080-exec-4 work
thread name : http-bio-8080-exec-4 finished
thread name : http-bio-8080-exec-14 work
thread name : http-bio-8080-exec-14 finished
thread name : http-bio-8080-exec-20 work
thread name : http-bio-8080-exec-20 finished
thread name : http-bio-8080-exec-10 work
thread name : http-bio-8080-exec-10 finished
thread name : http-bio-8080-exec-19 work
thread name : http-bio-8080-exec-19 finished
thread name : http-bio-8080-exec-21 work
thread name : http-bio-8080-exec-21 finished
thread name : http-bio-8080-exec-30 work
thread name : http-bio-8080-exec-30 finished
thread name : http-bio-8080-exec-12 work
thread name : http-bio-8080-exec-12 finished
thread name : http-bio-8080-exec-26 work
thread name : http-bio-8080-exec-26 finished
thread name : http-bio-8080-exec-22 work
thread name : http-bio-8080-exec-22 finished
thread name : http-bio-8080-exec-23 work
thread name : http-bio-8080-exec-23 finished
thread name : http-bio-8080-exec-13 work
thread name : http-bio-8080-exec-13 finished
thread name : http-bio-8080-exec-28 work
thread name : http-bio-8080-exec-28 finished
thread name : http-bio-8080-exec-5 work
thread name : http-bio-8080-exec-5 finished
thread name : http-bio-8080-exec-8 work
thread name : http-bio-8080-exec-8 finished
thread name : http-bio-8080-exec-3 work
thread name : http-bio-8080-exec-3 finished
thread name : http-bio-8080-exec-18 work
thread name : http-bio-8080-exec-18 finished
thread name : http-bio-8080-exec-14 work
thread name : http-bio-8080-exec-14 finished
thread name : http-bio-8080-exec-20 work
thread name : http-bio-8080-exec-20 finished
thread name : http-bio-8080-exec-10 work
thread name : http-bio-8080-exec-10 finished
thread name : http-bio-8080-exec-19 work
thread name : http-bio-8080-exec-19 finished
thread name : http-bio-8080-exec-21 work
thread name : http-bio-8080-exec-21 finished
thread name : http-bio-8080-exec-4 work
thread name : http-bio-8080-exec-5 work
thread name : http-bio-8080-exec-3 work
thread name : http-bio-8080-exec-6 work
thread name : http-bio-8080-exec-7 work
thread name : http-bio-8080-exec-4 finished
thread name : http-bio-8080-exec-6 finished
thread name : http-bio-8080-exec-5 finished
thread name : http-bio-8080-exec-3 finished
thread name : http-bio-8080-exec-7 finished
thread name : http-bio-8080-exec-9 work
thread name : http-bio-8080-exec-8 work
thread name : http-bio-8080-exec-9 finished
thread name : http-bio-8080-exec-8 finished
thread name : http-bio-8080-exec-10 work
thread name : http-bio-8080-exec-10 finished
thread name : http-bio-8080-exec-1 work
thread name : http-bio-8080-exec-1 finished
thread name : http-bio-8080-exec-11 work
thread name : http-bio-8080-exec-11 finished
thread name : http-bio-8080-exec-12 work
thread name : http-bio-8080-exec-12 finished
thread name : http-bio-8080-exec-13 work
thread name : http-bio-8080-exec-13 finished
thread name : http-bio-8080-exec-14 work
thread name : http-bio-8080-exec-14 finished
thread name : http-bio-8080-exec-16 work
thread name : http-bio-8080-exec-16 finished
thread name : http-bio-8080-exec-15 work
thread name : http-bio-8080-exec-15 finished
thread name : http-bio-8080-exec-14 work
thread name : http-bio-8080-exec-14 finished
thread name : http-bio-8080-exec-2 work
thread name : http-bio-8080-exec-2 finished
thread name : http-bio-8080-exec-24 work
thread name : http-bio-8080-exec-24 finished
thread name : http-bio-8080-exec-7 work
thread name : http-bio-8080-exec-11 work
thread name : http-bio-8080-exec-7 finished
thread name : http-bio-8080-exec-11 finished
thread name : http-bio-8080-exec-19 work
thread name : http-bio-8080-exec-19 finished
thread name : http-bio-8080-exec-4 work
thread name : http-bio-8080-exec-4 finished
thread name : http-bio-8080-exec-11 work
thread name : http-bio-8080-exec-11 finished
thread name : http-bio-8080-exec-15 work
thread name : http-bio-8080-exec-15 finished
thread name : http-bio-8080-exec-3 work
thread name : http-bio-8080-exec-3 finished
thread name : http-bio-8080-exec-7 work
thread name : http-bio-8080-exec-7 finished
thread name : http-bio-8080-exec-18 work
thread name : http-bio-8080-exec-18 finished
thread name : http-bio-8080-exec-18 work
thread name : http-bio-8080-exec-18 finished
thread name : http-bio-8080-exec-1 work
thread name : http-bio-8080-exec-1 finished
thread name : http-bio-8080-exec-17 work
thread name : http-bio-8080-exec-17 finished
thread name : http-bio-8080-exec-25 work
thread name : http-bio-8080-exec-25 finished
thread name : http-bio-8080-exec-2 work
thread name : http-bio-8080-exec-2 finished
thread name : http-bio-8080-exec-7 work
thread name : http-bio-8080-exec-7 finished
thread name : http-bio-8080-exec-23 work
thread name : http-bio-8080-exec-23 finished
thread name : http-bio-8080-exec-13 work
thread name : http-bio-8080-exec-13 finished
thread name : http-bio-8080-exec-19 work
thread name : http-bio-8080-exec-19 finished
thread name : http-bio-8080-exec-12 work
thread name : http-bio-8080-exec-12 finished
thread name : http-bio-8080-exec-6 work
thread name : http-bio-8080-exec-6 finished
thread name : http-bio-8080-exec-4 work
thread name : http-bio-8080-exec-4 finished
thread name : http-bio-8080-exec-21 work
thread name : http-bio-8080-exec-21 finished
thread name : http-bio-8080-exec-18 work
thread name : http-bio-8080-exec-18 finished
thread name : http-bio-8080-exec-1 work
thread name : http-bio-8080-exec-1 finished
thread name : http-bio-8080-exec-17 work
thread name : http-bio-8080-exec-17 finished
......
package jp.co.nec.aim.demo.servlet;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
public class Entrance {
private static final ReentrantLock lock = new ReentrantLock(false);
private static final Condition c = lock.newCondition();
public static void main(String[] args) {
lock.lock();
try {
c.await();
// do something
System.out.print(11);
c.notify();
} catch (InterruptedException e) {
} finally {
lock.unlock();
}
}
}