如何使无限 Thread 实例循环?
How to make an infinite Thread instances loop?
我想创建线程来操作它们(运行,等待,停止)。我知道怎么做一个一个实例
Class 实现 运行nable
public class ThreadRunner implements Runnable{ .....
Class 我创建对象的地方
ThreadRunner thread1 = new ThreadRunner ("thread1");
ThreadRunner thread2 = new ThreadRunner ("thread2");
.
.
.
thread1.start()
.
.
我想要一个仅在用户想要时结束的循环(可能带有布尔标志)。如何创建每 10 秒动态实例化一个线程的循环?
boolean stop = false;
List<Thread> threads = new ArrayList<Thread>();
while (!stop) {
Thread t = new ThreadRunner("Thread " + threads.size());
t.start();
threads.add(t);
// Do something here to check whether 'stop' should be updated.
// And wait for 10 seconds here
}
我想创建线程来操作它们(运行,等待,停止)。我知道怎么做一个一个实例
Class 实现 运行nable
public class ThreadRunner implements Runnable{ .....
Class 我创建对象的地方
ThreadRunner thread1 = new ThreadRunner ("thread1");
ThreadRunner thread2 = new ThreadRunner ("thread2");
.
.
.
thread1.start()
.
.
我想要一个仅在用户想要时结束的循环(可能带有布尔标志)。如何创建每 10 秒动态实例化一个线程的循环?
boolean stop = false;
List<Thread> threads = new ArrayList<Thread>();
while (!stop) {
Thread t = new ThreadRunner("Thread " + threads.size());
t.start();
threads.add(t);
// Do something here to check whether 'stop' should be updated.
// And wait for 10 seconds here
}