mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
package cn.hutool.socket;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.RuntimeUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Socket通讯配置
|
||||
@@ -14,7 +15,7 @@ public class SocketConfig implements Serializable{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** CPU核心数 */
|
||||
private static int CPU_COUNT = Runtime.getRuntime().availableProcessors();
|
||||
private static final int CPU_COUNT = RuntimeUtil.getProcessorCount();
|
||||
|
||||
/** 共享线程池大小,此线程池用于接收和处理用户连接 */
|
||||
private int threadPoolSize = CPU_COUNT;
|
||||
|
@@ -1,5 +1,8 @@
|
||||
package cn.hutool.socket.nio;
|
||||
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -11,9 +14,6 @@ import java.nio.channels.ServerSocketChannel;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.Iterator;
|
||||
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
|
||||
/**
|
||||
* 基于NIO的Socket服务端实现
|
||||
*
|
||||
@@ -130,7 +130,7 @@ public abstract class NioServer implements Closeable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
public void close() {
|
||||
IoUtil.close(this.selector);
|
||||
IoUtil.close(this.serverSocketChannel);
|
||||
}
|
||||
@@ -166,6 +166,7 @@ public abstract class NioServer implements Closeable {
|
||||
try {
|
||||
channel.configureBlocking(false);
|
||||
// 注册通道
|
||||
//noinspection MagicConstant
|
||||
channel.register(selector, ops.getValue());
|
||||
} catch (IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
|
@@ -18,7 +18,7 @@ public enum Operation {
|
||||
/** 接受连接操作 */
|
||||
ACCEPT(SelectionKey.OP_ACCEPT);
|
||||
|
||||
private int value;
|
||||
private final int value;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
|
Reference in New Issue
Block a user