Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带背景线程的Java WebSocket_Java_Multithreading_Websocket - Fatal编程技术网

带背景线程的Java WebSocket

带背景线程的Java WebSocket,java,multithreading,websocket,Java,Multithreading,Websocket,我是Java新手&我需要以下问题的帮助: 我开始学习websocket应用程序的工作原理。我的代码使用javax.websocket实现websocket服务器,该服务器将POJO转换为websocket侦听器,如下所示: @ServerEndpoint("/sample") public class SampleSocket { private static Set<Session> clients = Collections.synchronizedSet(new Has

我是Java新手&我需要以下问题的帮助:

我开始学习websocket应用程序的工作原理。我的代码使用javax.websocket实现websocket服务器,该服务器将POJO转换为websocket侦听器,如下所示:

@ServerEndpoint("/sample")
public class SampleSocket {
    private static Set<Session> clients = Collections.synchronizedSet(new HashSet<Session>());

    @OnOpen
    public void onOpen(Session session) {
        // handle connection open here
    }

    @OnClose
    public void onClose(Session session) {
        // handle connection close here
    }

    @OnMessage
    public void onMessage(Session session) {
        // handle incoming message here
    }

    @OnError
    public void onError(Session session) {
        // handle error here
    }
}
@ServerEndpoint(“/sample”)
公共类样本集{
private static Set clients=Collections.synchronizedSet(new HashSet());
@奥诺彭
公共开放(会议){
//在这里打开连接
}
@一次
公共void onClose(会话){
//在这里处理连接
}
@OnMessage
公共void onMessage(会话){
//在这里处理传入消息
}
@一个错误
公开作废申报人(会议){
//在这里处理错误
}
}
以上代码有效

现在,我想创建一个新的后台线程,在服务器进入监听模式和/或跟踪其他信息之前做一些准备。但是我不知道如何实例化这个后台线程。SampleSocket构造函数似乎不起作用


提前感谢。

@PostConstruct将有助于解决这种情况