作者:duqi
想了下,应该是这个原因:interrupted()方法是静态方法,isInterrupted()是实例方法,在这个例子中FileSearch是实现了Runnable接口,因此只能通过Thread调用它的实例方法;如果使用extends(继承),让FileSearch继承Thread类的话,就可以使用isInterrupted()方法了
View Article
More Pages to Explore .....
Thread.currentThread 获取当前线程的实例。 Thread 是个线程类。
View Article请问为什么在这个程序中用interrupted()方法判断是否中断,而不是用isInterrupted(),是有什么特殊的原因吗?
View Article想了下,应该是这个原因:interrupted()方法是静态方法,isInterrupted()是实例方法,在这个例子中FileSearch是实现了Runnable接口,因此只能通过Thread调用它的实例方法;如果使用extends(继承),让FileSearch继承Thread类的话,就可以使用isInterrupted()方法了
View Article或者用Thread.currentThread()获取当前线程,再调用isInterrupted()来获取状态
View Article