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 26 27 28 29 30 31 32 33 34 35 36
| package com.redisc;
import io.netty.channel.EventLoop; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.GenericFutureListener; import lombok.extern.slf4j.Slf4j;
import java.io.IOException; import java.util.concurrent.*;
@Slf4j(topic = "c.MultiThreadServer") public class MultiThreadServer {
public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { NioEventLoopGroup nioEventLoopGroup = new NioEventLoopGroup(); EventLoop eventLoop = nioEventLoopGroup.next();
Future<Integer> future = eventLoop.submit(new Callable<Integer>() { @Override public Integer call() throws Exception { log.debug("执行计算"); Thread.sleep(1000); return 50; } }); future.addListener(new GenericFutureListener<Future<? super Integer>>() { @Override public void operationComplete(Future<? super Integer> future) throws Exception { log.debug("结果是 {}", future.getNow());
} }); } }
|