while (true) {
System.out.println("3");
Thread.sleep(1000);
}
Làm thế nào để thu hồi thread này vậy ạ
while (true) {
System.out.println("3");
Thread.sleep(1000);
}
Làm thế nào để thu hồi thread này vậy ạ
public class InterruptThread {
public static void main(String[] args) throws Exception {
Thread newThread = new Thread(() -> {
while (true) {
System.out.println("current thread: " + Thread.currentThread().getName());
}
});
newThread.start();
Thread.sleep(10);
newThread.interrupt();
while (true) {
Thread.sleep(10);
}
}
}