线程同步的方法
来源:互联网 发布:中美南海撞机事件 知乎 编辑:程序博客网 时间:2024/05/04 08:11
一 线程同步的方法
1 ReentrantLock()
a)加锁
ReentrantLock lock = new ReentrantLock();
{
lock.lock();
try{
}
finally{
lock.unlock();
}
}
b)condition variable
Condition fund;
{
lock.lock();
try{
while(a < b)
fund.await();
fund.signalAll();
}
finally{
lock.unlock();
}
}
2 synchronized
a)加锁
synchronized void transfer(){
}
Object lock = new Object();
void transfer(){
synchronized{
}
}
b)condition variable
synchronized void transfer(){
wait();
try{
while(a < b)
fund.await();
nitifyAll();
}
finally{
lock.unlock();
}
}
- 线程的同步-同步方法
- 线程同步的方法
- 线程同步的方法
- 线程同步的方法
- 线程同步的方法
- 线程同步的方法
- 线程同步的方法
- 线程同步的方法
- 线程同步的方法
- 线程同步的方法
- 线程同步的方法
- 线程同步的方法
- 线程同步的方法
- 线程同步的方法
- 线程同步的方法
- 线程同步的方法
- 线程同步的方法
- 线程同步的方法
- 中国开放平台年度奖项评选
- flex puremvc与pipe通信的一些心得
- Hibernate关联映射-----一对多关联和多对一关联(续)
- c#基础问题
- forward和redirect区别
- 线程同步的方法
- typedef 的用法(转载)
- mssql常用存储过程
- 专利地图制作及解析研究
- Ajax中Get和Post的区别
- 关于简单的线程池
- 接口的作用
- shell test(too many arguments)
- 根据文件后缀名判断上传文件是否合法