一个简单的java锁Lock的实现
2013-10-17 17:15
399 查看
public class Lock { private volatile boolean isLocked = false; private Thread lockingThread = null; public synchronized void lock() throws InterruptedException { while (isLocked) { wait(); } isLocked = true; lockingThread = Thread.currentThread(); } public synchronized void unLock() { if (this.lockingThread != Thread.currentThread()) { throw new IllegalMonitorStateException("Calling thread has not locked this lock"); } isLocked = true; lockingThread = null; notify(); } }
相关文章推荐
- java 多线之用ReadWriteLock实现 一个简单缓存
- Java实现一个简单的线程池
- Java实现一个简单的RPC框架(一) 本地调用
- Java实现一个简单的RPC框架(四) 编码和解码
- 一个简单的线程池实现(java版)
- 在Java中使用多线程结合断点续传实现一个简单的文件下载器
- JAVA编写的一个简单的Socket实现的HTTP响应服务器进阶版
- 用java的spring实现一个简单的IOC容器示例代码
- JAVA编写的一个简单的Socket实现的HTTP响应服务器
- java实现一个简单的Web服务器实例解析
- 一个UDP(多播)局域聊天的简单实现 (JAVA)
- 一个简单的java回调函数的实现
- 如何用java 5分钟实现一个最简单的mysql代理服务器?
- 搜索引擎----Java实现一个简单的网络爬虫
- 使用 java 实现一个简单的 markdown 语法解析器
- JAVA实现的一个简单的死锁(附解释)
- 简单说明什么是递归?什么情况会使用?并使用Java实现一个简单的递归程序。
- java实现一个简单的网络爬虫代码示例
- java实现一个简单的Web服务器
- 【java学习记录】9.实现一个简单的计算器