ReentrantLock
来源:互联网 发布:南昌大学软件学院吧 编辑:程序博客网 时间:2024/06/03 19:31
/* */ private Lock getLock(String lockKey) {/* 167 */ Lock l = (Lock)this.locks.get(lockKey);/* 168 */ if (l == null) {/* 169 */ synchronized (this.lock) {/* 170 */ l = (Lock)this.locks.get(lockKey);/* 171 */ if (l == null) {/* 172 */ l = new ReentrantLock();/* 173 */ this.locks.put(lockKey, l);/* */ }/* */ }/* */ }/* 177 */ return l;/* */ }
获取锁代码片段。
/* */ private String nextOid(String sid)/* */ {/* 102 */ if (StringUtils.isBlank(sid)) {/* 103 */ sid = "uapcloud";/* */ }/* */ /* 106 */ String key = sid;/* 107 */ if (StringUtils.isBlank(key)) {/* 108 */ throw new RuntimeException("schema code can not be null! please check global conf and context info!");/* */ }/* */ /* */ /* 112 */ Lock l = getLock(key);/* */ /* 114 */ OidCounter oidCounter = null;/* 115 */ String oidBase = null;/* 116 */ String nextOid = null;/* */ /* */ try/* */ {/* 120 */ l.lock();/* */ /* 122 */ oidCounter = (OidCounter)oidMap.get(key);/* 123 */ if (oidCounter == null) {/* 124 */ oidCounter = new OidCounter();/* 125 */ oidMap.put(key, oidCounter);/* */ }/* */ /* 128 */ if ((oidCounter.amount % OID_AMOUNT == 0) || (0 == oidCounter.amount)) {/* 129 */ oidBase = getNewBaseId(key);/* */ } else {/* 131 */ oidBase = oidCounter.oidBase;/* */ }/* */ /* 134 */ nextOid = UapOidAlgorithm.getInstance(oidBase).nextOidBase();/* 135 */ oidCounter.oidBase = nextOid;/* 136 */ oidCounter.amount += 1;/* */ } catch (Exception e) {/* 138 */ LOGGER.error("get oid error!", e);/* 139 */ throw e;/* */ }/* */ finally {/* 142 */ l.unlock();/* */ }/* */ /* 145 */ if (nextOid == null) {/* 146 */ return null;/* */ }/* */ /* 149 */ return getWholeOid(sid, nextOid);/* */ }
阅读全文
0 0
- ReentrantLock
- ReentrantLock
- ReentrantLock
- ReentrantLock
- ReentrantLock
- ReentrantLock
- ReentrantLock &&
- ReentrantLock
- ReentrantLock
- ReentrantLock
- ReentrantLock
- ReentrantLock
- ReentrantLock
- ReentrantLock
- ReentrantLock
- ReentrantLock
- ReentrantLock
- ReentrantLock
- [python]leetcode(239). Sliding Window Maximum
- 二,mysql字符串操作函数
- Web Server之如何支持https
- 关于reload(sys) sys.defaultencoding问题
- Qt入门-控件颜色面板类QPalette
- ReentrantLock
- 常用SQL查询语句
- 135. Candy
- 第五篇 按键
- mac使用codelite运行程序没有输出
- 归并排序总结
- JavaScript函数向未声明的变量分配值
- Hibernate 加载策略
- NGUI_创建及Label的使用_001