线程问题,通知

时间:2019-07-10 17:19:50

标签: java thread-safety wait notify

我有一个for循环,其中一个命令调用线程。

public void test{
    for(int i = 0 i < MAX; i++){
        callThisMethod();
// I need to put something here in order to wait until the threadX has finished
    }
}

private void callThisMethod(){
    Thread threadX = new Thread(){
        public void run(){
            // do something quite time consuming
        }
    };
    threadX.start();
}

在这种情况下,我不确定如何使用java.lang.Object.wait()和java.lang.Object.notify(),因此循环冻结,直到threadX完成其工作为止。

0 个答案:

没有答案
相关问题