I'd like to use Publish/Subscribe in our XPages application, in Java, e.g. with Jedis. The application runs in a multi-user setting, and when one user makes some changes to a document we'd like to see those changes reflected on other users' screens. In theory that could be done using PubSub: when the change is applied, a "document modified" message is published and sent to the party or parties that subscribed to this message. The subscriber part I'd like to put in a Thread, so that the object that subscribed can react immediately when the message is received.
The scope for most objects that use subscribe is viewscope, they should be destroyed when viewscope is destroyed. But what happens when the object is abandoned and the subscriber thread is still there? For instance, how can I tell the JVM that the Thread can safely be stopped and scrapped by the garbage collector?
I have yet to try this, so I have no code that I can show, but here's the questions I have:
- am I right, will the Thread continue to run even when viewscope is destroyed?
- is there a way to create a garbage-collectable Thread?
- or maybe: is there some API that does PubSub in the multi-threaded XPages environment?