62,612
社区成员
发帖
与我相关
我的任务
分享
public class Test1 extends Thread{
public boolean isCanceled;
@Override
public void run() throws NullPointerException{
throw new NullPointerException();
}
}
public class Test2 extends Thread{
@Override
public void run(){
try{
new Test1().start();
}catch(NullPointerException e){
System.out.println("helloworld");
e.printStackTrace();
}
}
public static void main(String[] args) {
new Test2().start();
}
}
package callBack;
public interface TimeOut {
public void say();
}
package callBack;
[code=Java]public class ThreadCount implements Runnable {
private ThreadDo threadDo = null;
public ThreadCount() {
super();
}
public ThreadCount(ThreadDo threadDo) {
super();
this.threadDo = threadDo;
}
@Override
public void run() {
synchronized (this) {
while (true) {
try {
this.wait(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
this.threadDo.setFlag(true);
break;
}
}
}
}
package callBack;
public class Test {
public static void main(String[] args) {
ThreadDo threadDo = new ThreadDo();
threadDo.setTimeOut(new TimeOut() {
@Override
public void say() {
System.out.println("time out!");
}
});
ThreadCount threadCount = new ThreadCount(threadDo);
new Thread(threadCount).start();
new Thread(threadDo).start();
}
}