Division
Thread-Per-Message
Thread 实现
public static void main(String[] args) throws IOException {
try (ServerSocketChannel ssc = ServerSocketChannel.open().bind(new InetSocketAddress(8080))) {
try {
while (true) {
SocketChannel sc = ssc.accept();
new Thread(() -> {
try {
ByteBuffer rb = ByteBuffer.allocate(2048);
sc.read(rb);
rb.flip();
sc.write(rb);
sc.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}).start();
}
} finally {
ssc.close();
}
}
}Fiber 实现
Work Thread
创建线程池的建议
避免线程死锁
生产者-消费者
Last updated
