Java ServerEndpointConfig.Configurator实例应该是线程安全的吗?
我想在websocket连接之间共享一些信息。共享数据有点复杂,因此我无法使用Java ServerEndpointConfig.Configurator实例应该是线程安全的吗?,java,multithreading,jakarta-ee,websocket,tyrus,Java,Multithreading,Jakarta Ee,Websocket,Tyrus,我想在websocket连接之间共享一些信息。共享数据有点复杂,因此我无法使用EndpointConfig.getUserProperties()。我想扩展ServerEndpointConfig.Configurator并添加我自己的数据结构。(我不想覆盖其他方法,如getEndpointInstance)。问题是我应该使用线程安全的数据结构吗?或者,我可以使用任何数据结构,web套接字容器将保证以安全的方式访问我的ServerEndpointConfig.Configurator实例。这感觉
EndpointConfig.getUserProperties()
。我想扩展ServerEndpointConfig.Configurator
并添加我自己的数据结构。(我不想覆盖其他方法,如getEndpointInstance
)。问题是我应该使用线程安全的数据结构吗?或者,我可以使用任何数据结构,web套接字容器将保证以安全的方式访问我的ServerEndpointConfig.Configurator
实例。这感觉太粗糙了。Configurator应该是不可变的(检查),而不是共享点。
在JavaEE环境中有一种更好的方法。
Websocket规范为CDI/EJB提供了一些支持。您可以插入
@ApplicationScoped
或@Singleton
bean,并使用它共享数据(该bean必须同步)。这里有一个共享的反例