Home > Mobile >  If the child thread collapse in your code, how to make the main thread is not affected
If the child thread collapse in your code, how to make the main thread is not affected

Time:10-04

Opened a lot of child thread in the project, some child thread collapse cause the program interface caton collapse, even how to ensure the child thread collapse, the main thread is still working

CodePudding user response:

The coding problem fault tolerance, there is something wrong with the child thread running your exit thread break, or return, and then send a Message to tell the main thread have error, generally will not affect the main thread,

CodePudding user response:

Catch mistakes and then correct it, such as the upstairs said in the Message tells the main thread,

CodePudding user response:

Across threads catch exceptions not captured
Thread. SetDefaultUncaughtExceptionHandler (new Thread. UncaughtExceptionHandler () {

@ Override
Public void uncaughtException (Thread t, Throwable e) {
//
}
});
  • Related