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
Post a Comment