设置捕获线程出错
Thread sendLocationTread = new Thread(sendUserLocationThread);
sendLocationTread.setUncaughtExceptionHandler(exceptionHadler);
sendLocationTread.start();
/**
* 百度地图获取不到位置 重启线程 最多重启5次
*/
private UncaughtExceptionHandler exceptionHadler = new UncaughtExceptionHandler() {
private int restartTime = 0;
private final static int MAXTIME = 5;
@Override
public void uncaughtException(Thread t, Throwable e) {
if (restartTime < MAXTIME) {
System.out.println("=restart");
Thread thread = new Thread(sendUserLocationThread);
thread.setUncaughtExceptionHandler(this);
thread.start();
restartTime++;
}
}
};
线程中就可以设置throw 这样就可以重启线程
if (BDERROR) {
throw new RuntimeException();
}