多线程这个Java线程什么时候停止
我只是想知道当timer
函数完成时,线程会停止吗?或者我需要做些什么来阻止它
public void testing() {
Thread thread = new Thread(new Runnable() {
public void run() {
synchronized(this) {
timer();
}
}
});
thread.start();
}
public void timer() {
boolean active = true;
long start = System.currentTimeMillis() / 1000L;
while (active) {
long finish = System.currentTimeMillis() / 1000L;
if (finish - start >= 20) {
System.out.println("Finished");
active = false;
}
}
}
共 (0) 个答案