1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| @Slf4j public class TestNettyPromise { public static void main(String[] args) throws ExecutionException, InterruptedException { EventLoop eventLoop = new NioEventLoopGroup().next(); DefaultPromise<Integer> promise = new DefaultPromise<>(eventLoop); new Thread(() -> { log.debug("开始计算..."); try { int i = 1 / 0; Thread.sleep(1000); promise.setSuccess(80); } catch (Exception e) { e.printStackTrace(); promise.setFailure(e); }
}).start(); log.debug("等待结果..."); log.debug("结果是: {}", promise.get()); } }
|