fix:TestJdkFuture测试

上级 61ef5640
......@@ -14,6 +14,7 @@ target/
.sts4-cache
### IntelliJ IDEA ###
*.idea
.idea
*.iws
*.iml
......
......@@ -15,7 +15,7 @@ import java.net.InetSocketAddress;
import java.util.Scanner;
/**
* 客户端添加Scanner输入
* 客户端同步处理关闭之后的操作
*
* @author : qinyingjie
* @version : 2.2.0
......
......@@ -16,7 +16,7 @@ import java.net.InetSocketAddress;
import java.util.Scanner;
/**
* 客户端添加Scanner输入
* 客户端优雅关闭shutdownGracefully
*
* @author : qinyingjie
* @version : 2.2.0
......@@ -26,9 +26,10 @@ import java.util.Scanner;
public class TestEventLoop_02_client {
public static void main(String[] args) throws InterruptedException {
//1.启动类
final NioEventLoopGroup group = new NioEventLoopGroup();
final ChannelFuture channelFuture = new Bootstrap()
// 2.添加 EventLoop
.group(new NioEventLoopGroup())
.group(group)
//3.选择客户端channel实现
.channel(NioSocketChannel.class)
// 4.添加处理器4
......@@ -62,6 +63,7 @@ public class TestEventLoop_02_client {
@Override
public void operationComplete(ChannelFuture channelFuture) throws Exception {
log.debug("处理关闭之后的操作");
group.shutdownGracefully();//优雅关闭
}
}
);
......
package com.kwan.shuyu.heima.netty_05_future;
import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.*;
/**
* Jdk Future 测试
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/4/26 21:07
*/
@Slf4j
public class TestJdkFuture {
public static void main(String[] args) throws Exception {
//1.线程池
ExecutorService service = Executors.newFixedThreadPool(2);
//2.提交任务
Future<Integer> future = service.submit(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
Thread.sleep(1000);
return 50;
}
});
//3.主线程通过future 来获取结果
log.info("等待处理结果");
log.info("处理结果是={}", future.get());
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册