Jetty Websocket IdleTimeout

后端 未结 2 1669
执笔经年
执笔经年 2020-12-20 19:24

I\'ve been working on annotated websockets lately, with the Jetty API (9.4.5 release) , and made a chat with it.

However i got an issue, after 5 minute

相关标签:
2条回答
  • 2020-12-20 20:05

    Annotated WebSockets have their own timeout settings in the annotation.

    @WebSocket(maxIdleTime=30000)
    
    0 讨论(0)
  • 2020-12-20 20:20

    The annotation @WebSocket has option:

    int maxIdleTime() default -2;
    

    In fact it's not clear what does it mean.

    If you check implementation, you can find:

    if (anno.maxIdleTime() > 0)
    {
    this.policy.setIdleTimeout(anno.maxIdleTime());
    }
    

    method implementation:

    /**
     * The time in ms (milliseconds) that a websocket may be idle before closing.
     * 
     * @param ms
     *            the timeout in milliseconds
     */
    public void setIdleTimeout(long ms)
    {
        assertGreaterThan("IdleTimeout",ms,0);
        this.idleTimeout = ms;
    }
    

    and finally:

    /**
     * The time in ms (milliseconds) that a websocket may be idle before closing.
     * <p>
     * Default: 300000 (ms)
     */
    private long idleTimeout = 300000;
    

    Conclusion: negative value apply default behavior (300000 ms). You need to configure 'idleTimeout' according your business value.

    PS: solved my case with:

    @WebSocket(maxIdleTime = Integer.MAX_VALUE)
    
    0 讨论(0)
提交回复
热议问题