1700450139
1700450140
public TcpServer(){
1700450141
1700450142
Thread t=new Thread(this);
1700450143
1700450144
t.setUncaughtExceptionHandler(new TcpServerExceptionHandler());
1700450145
1700450146
t.start();
1700450147
1700450148
}
1700450149
1700450150
@Override
1700450151
1700450152
public void run(){
1700450153
1700450154
//正常业务运行,运行3秒
1700450155
1700450156
for(int i=0;i<3;i++){
1700450157
1700450158
try{
1700450159
1700450160
Thread.sleep(1000);
1700450161
1700450162
System.out.println(“系统正常运行:”+i);
1700450163
1700450164
}catch(InterruptedException e){
1700450165
1700450166
e.printStackTrace();
1700450167
1700450168
}
1700450169
1700450170
}
1700450171
1700450172
//抛出异常
1700450173
1700450174
throw new RuntimeException();
1700450175
1700450176
}
1700450177
1700450178
//异常处理器
1700450179
1700450180
private static class TcpServerExceptionHandler implements
1700450181
1700450182
Thread.UncaughtExceptionHandler{
1700450183
1700450184
@Override
1700450185
1700450186
public void uncaughtException(Thread t, Throwable e){
1700450187
1700450188
//记录线程异常信息
[
上一页 ]
[ :1.700450139e+09 ]
[
下一页 ]