嵌入式码头的多个实例
我使用 Maven 构建配置 (jetty:run) 从 Eclipse 运行嵌入式 jetty。服务器正常启动:
2011-07-07 13:48:11.915:INFO::Started [email protected]:8080 STARTING
[INFO] Started Jetty Server
[INFO] Starting scanner at interval of 10 seconds
然后,我启动另一个实例侦听同一端口(8080)。它也正常启动。多个实例如何同时运行并监听同一个端口?顺便说一句,我的网络应用程序工作正常,所有请求都发送到第一个实例,关闭它后,请求将发送到第二个实例。 谢谢
I run an embedded jetty from eclipse using maven build configuration (jetty:run). The server starts properly:
2011-07-07 13:48:11.915:INFO::Started [email protected]:8080 STARTING
[INFO] Started Jetty Server
[INFO] Starting scanner at interval of 10 seconds
Afterwards, I startup another instance listening to the same port (8080). It started properly as well. How does it possible that several instances simultaneously running and listening to the same port? BTW, my web application works fine and all the requests are going to the first instance, after shutting it down, the requests are following to the second instance.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是
SelectChannelConnector
的行为,它使用java.nio
选择器而不是java.net.Socket
。我不确定如何或为什么允许两个实例“侦听”同一端口(我什至不确定“侦听”是否是用于 java.nio 的正确词)。不过,您看到的行为是一致的 - 第二个SelectChannelConnector
将在第一个 SelectChannelConnector 停止后开始接收消息。您可以通过将
SelectChannelConnector
替换为SocketConnector
来重现“传统”行为。This is the behaviour of the
SelectChannelConnector
, which usesjava.nio
selectors instead ofjava.net.Socket
. I'm not sure how or why two instances are allowed to "listen" to the same port (I'm not even sure if "listen" is the right word to use forjava.nio
). The behaviour you're seeing is consistent, though - the secondSelectChannelConnector
will start receiving the messages after the first one has stopped.You can reproduce the "traditional" behaviour by replacing
SelectChannelConnector
withSocketConnector
.