JavaでThreadを停止する方法

Javaコード:
package startnews24;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
public static void main(String[] args) {
Worker work = new Worker();
work.start();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
work.setDone(Boolean.parseBoolean(br.readLine()));
} catch (IOException e) {
e.printStackTrace();
}
}
}

class Worker extends Thread {
private volatile boolean done = false; //volatileを利用
@Override
public void run() {
int i = 0;
while(!done) {
System.out.println(“番号: " + i++);
}
}
/*getter,setter*/
public boolean isDone() {
return done;
}
public void setDone(boolean done) {
this.done = done;
}
}

Java

Posted by arkgame