举个例子
class MyThread implements Runnable{
@Override
public void run() {
// TODO Auto-generated method stub
try {
Thread.sleep(1000);
} catch (Exception e) {
// TODO: handle exception
return;
}
}
}
public class ThreadDemo {
public static void main(String args[]){
MyThread mt=new MyThread();
Thread t=new Thread(mt,"线程");
t.start();
try {
Thread.sleep(1000);
} catch (Exception e) {
// TODO: handle exception
return;
}
t.interrupt(); }
}
希望对你有帮助! |