java - How can I know if a task submitted to executor threw exception? -


if run thread in executorservice there way know thread did not throw exception when started execution?

as per the javadoc, can submit runnable the executor using submit()

    executorservice service = executors.newsinglethreadexecutor();     future f = service.submit(new runnable() {         @override         public void run() {             throw new runtimeexception("i failed no reason");         }     });     try {         f.get();                 } catch (executionexception ee) {         system.out.println("execution failed " + ee.getmessage());     } catch (interruptedexception ie) {         system.out.println("execution failed " + ie.getmessage());     } 

this method work when exceptions unchecked. if have checked exceptions, rethrow them wrapped in runtimeexception or use teh callable instead of runnable interface.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -