参见https://stackoverflow.com/questions/41810306/appointment-scheduling....
支持session。最近添加了setIdleTimeout(长毫秒),以支持我们目前正在做的JSR-356 (javax.websocket)工作。
然而,在9.0.0。在RC2中,您可以执行以下操作,以便在创建会话之前尽早设置空闲超时(这正在修复,希望将在RC3中实现)
服务器端选项A: WebSocketServlet init-param
在websocket servlet的WEB-INF/web.xml
中,指定以下初始化参数
<init-param>
<param-name>maxIdleTime</param-name>
<param-value>10000</param-value>
</init-param>
Server Side option B: As policy change on WebSocketFactory
在你的WebSocketServlet。配置(WebSocketServletFactory factory)调用
@Override
public void configure(WebSocketServletFactory factory)
{
factory.getPolicy().setIdleTimeout(10000);
}
客户端选项A: As WebSocketClient设置
WebSocketClient client = new WebSocketClient();
client.getPolicy().setIdleTimeout(10000);
client.start();
带注释的@WebSocket选项
这将适用于服务器端或客户端websockets。
注意:你不能把WebSocketListener和@WebSocket注释混合在一起
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
@WebSocket(maxIdleTime=10000)
public class MySocket
{
@OnWebSocketClose
public void onClose(int statusCode, String reason)
{
}
@OnWebSocketConnect
public void onConnect(Session sess)
{
}
@OnWebSocketError
public void onError(Throwable cause)
{
}
@OnWebSocketMessage
public void onText(String message)
{
}
}