`

线程互动收集

阅读更多

1.

// wait till login response has sent out
while(true) {
    if(State.TIMED_WAITING.equals(bindhandlerMainThread.getState())) {
        break;
    }
					
    try {
        Thread.sleep(100);
    } catch(InterruptedException e) {
        e.printStackTrace();
    }
}

 这是一种方法,虽然粒度较粗,用wait notify,要在不同类中去获得两次对象锁的引用(一次wait,一次notify)也麻烦,而这个,只要获得一次需要被观察的线程引用就行。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics