java - JDK8 CompletableFuture.supplyAsync how to deal with interruptedException -


completablefuture.supplyasync( () -> {     transporter.write(req);     //here take value blocking queue,will throw interruptedexception     return responsequeue.take(); },  executorservice); 

the common method deal interruptedexception either interrupt again or direct throw interruptedexception, both cannot work. have idea?

i change code this.

    completablefuture<rep> result = new completablefuture<>();     completablefuture.runasync(() -> {          transporter.write(req);         try {             rep rep = responsequeue.take();             result.complete(rep);         } catch (interruptedexception e) {             result.completeexceptionally(e);             thread.currentthread().interrupt();         } catch (exception e) {             result.completeexceptionally(e);         }      }, executorservice);     return result; 

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -