文章列表
服务端:
public class MultiServerPool {
private ServerSocket serverSocket;
private ExecutorService pool;// 线程池
private final int POOL_SIZE = 10;// 单个CPU线程池大小
public void service() {
try {
serverSocket = new ServerSocket(2046);
// Runtime的availableProcessor()方法返回当前系统的CPU数目.
pool ...
服务端:
实现Runnable接口:
public class MultiServerRunnable {
private ServerSocket server;
public void service() {
try {
server = new ServerSocket(2046);
while (true) {
Socket client = server.accept();
Thread thread = new Thread(new Handler(client));
thread.start();
...
服务端:
public class ServerSide {
public void service() {
ServerSocket server = null;
Socket client = null;
BufferedReader is = null;
PrintWriter os = null;
try {
server = new ServerSocket(2046);
System.out.println("服务器启动...");
client = server.accept();
...