1.代码的结构简单描述如下:
boolean flag_01 = true;
for (int i = 0; i < 5; i++) {
new Thread(new Runnable(){},"生产者").start();
new Thread(new Runnable(){new Runnable(){//消费线程},flag_01 = false},"消费者").start();
whiel(flag_01){}
}
请问,如何控制,当消费线程执行完之后,再执行flag_01 = false; 线程中套线程,如果获得最内层的线程,使之完成之后,再执行。。
An object is passed in the consumer thread. This object contains the attribute flag_01. After the thread execution is completed, call a function of this object, set flag_01 to false, and keep reading the flag_01 attribute of this object in the outer layer to see if it is false. .
I don’t understand the code you wrote.
If you want to have a sequential execution relationship between multiple threads, you can consider
java.util.concurrent.CountDownLatch
or you have written the code completely. We'll discuss it later.