我正在尝试向Runnable接口添加异常处理程序 这是我的代码:
ExecutorService executor = Executors.newCachedThreadPool();
public ResponseEntity<String> handleNotifications(){
Runnable r1 =() ->{
//some code
};
executor.execute(r1);
}
如何将异常处理程序添加到runnable接口。
答案 0 :(得分:0)
向Runnable
接口添加(已检查)异常处理程序几乎等同于Callable<T>
接口。我建议调查一下以解决您的问题,否则您只需使用try-catch
块。
ExecutorService executor = Executors.newCachedThreadPool();
public ResponseEntity<String> handleNotifications(){
executor.execute(() -> {
try {
// Code here...
} catch (Exception e) {
// Handle exception here...
}
});
return ...
}