我遇到了来自Apache Mina的示例代码。代码粘贴在下面,但可以找到here。
public static void main(String[] args) throws Exception {
if (args.length != 3) {
System.out.println(Main.class.getName()
+ " <proxy-port> <server-hostname> <server-port>");
return;
}
// Create TCP/IP acceptor.
NioSocketAcceptor acceptor = new NioSocketAcceptor();
// Create TCP/IP connector.
IoConnector connector = new NioSocketConnector();
// Set connect timeout.
connector.setConnectTimeoutMillis(30*1000L);
ClientToProxyIoHandler handler = new ClientToProxyIoHandler(connector,
new InetSocketAddress(args[1], Integer.parseInt(args[2])));
// Start proxy.
acceptor.setHandler(handler);
acceptor.bind(new InetSocketAddress(Integer.parseInt(args[0])));
System.out.println("Listening on port " + Integer.parseInt(args[0]));
}
我运行了代码。事实证明,在打印出“侦听端口......”后,JVM继续运行。我不明白为什么那是可能的。有人可以解释一下吗?非常感谢你。