套接字积压是什么意思?
例如我有网络服务
@WebService
public class Calculator {
public int sum(int a, int b) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return a + b;
}
public static final int threadCount = 10;
public static void main(String[] args) throws IOException {
Executor manyThreads = Executors.newFixedThreadPool(threadCount);
HttpServer server = HttpServer.create(new InetSocketAddress(8989), threadCount);
server.setExecutor(manyThreads);
server.start();
Endpoint ep = Endpoint.create(new Calculator());
HttpContext context = server.createContext("/calc");
ep.publish(context);
}
}
和网络服务客户端
public static void main(String[] args) throws IOException {
CalculatorService service = new CalculatorService();
final Calculator calc = service.getCalculatorPort();
Executor executor = Executors.newFixedThreadPool(100);
for (int i = 0; i < 1000000; ++i) {
executor.execute(new Runnable() {
public void run() {
try {
int currentThreads = runningThreads.incrementAndGet();
int res = calc.sum(10, 10);
System.out.println("Running threads: " + currentThreads + " Result: " + res);
} catch (ClientTransportException e) {
System.out.println("connection refused");
} finally {
runningThreads.decrementAndGet();
}
}
});
}
System.in.read();
}
在服务器上只有 10 个工作线程,并且 backlog 设置为 10,所以可以有 10 个接受的连接和 10 个等待 backlog 的连接,并且任何其他连接都将被拒绝,对吗?
可能不是因为我没有得到 ClientTransportException。
您能否解释一下连接发生了什么以及为什么没有 ClientTransportException。