/**
*
* 此类主要用来处理线程同步屏蔽模型比如批线程运行必须在最后个线程运行
* 完后才能进行下步操作那么就可以创建个锁对象锁对象提供个线程等待其他线程
* 思路方法如果当前线程运行时还有未运行线程则此线程wait否则此线程唤醒其他阻塞
* 线程进而最终完成线程运行
* */
public LockObject {
private totalThread = 0;
private currentThread = 0;
public LockObject( totalThread) {
this.totalThread = totalThread;
this.currentThread = 1;
}
public synchronized void waitForOtherThread {
(this.currentThread < this.totalThread) {
this.currentThread;
try {
this.wait;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.prStackTrace;
}
} {
this.currentThread = 1;
notyAll;
}
}
public getTotalThread {
totalThread;
}
public void TotalThread( totalThread) {
this.totalThread = totalThread;
}
public getCurrentThread {
currentThread;
}
public void CurrentThread( currentThread) {
this.currentThread = currentThread;
}
}
="xspace-totlerecord">2="xspace-totlepages">1/2="xspace-current">12>
最新评论