0
我想從運行線程捕獲異常並在調用線程中處理它。我將如何以最好的方式?從運行線程捕獲異常
try {
Runnable connect = new Runnable() {
public synchronized void run() {
try {
... some code requiring long time
} catch(Exception e) {
..I want to catch here and send to calling thread
}
}
}
synchronized(connect) {
new Thread(connect).start();
connect.wait();
...if exception then handle it
...keep on with code if no exception occurred
}
} catch(Exception e) {
}
我想你需要使用併發相關的類和Future.http://www.vogella.com/articles/JavaConcurrency/article.html#futures – kosa