public static void main(String[] args) {
Thread.currentThread().interrupt();
System.out.println(Thread.currentThread().isInterrupted());
}
调用interrupt后,线程并不会立即中止,只不过isInterrupted()返回的是false
public static void main(String[] args) {
Thread t=new Thread(){
public void run() {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("run...........");
}};
t.start();
try {
t.join(1000);
} catch ( Exception e) {
e.printStackTrace();
}
}
t.join()会阻塞,但是当阻塞时间到时,并不会抛出异常,它只是接着向下走。
t.join()很像这样的意思:我等你2小时,你如果做完了,我们就一起走,否则到时间我就不管你了,我走自己的。