currently I try integrating Apache CouchDB change notifications into our Spring webapp. The idea, generally, is to have a long-running HTTP GET request to the CouchDB backend from some Java client class which, therefore, also is a long-running thread (to start with the application context and to terminate with the application context being terminated) providing some sort of event handlers invoked whenever there's some change in the CouchDB database structure.
At the moment, I try to find the most "clean" way how to include this into the Spring application. My initial attempt was to introduce a ServletContextListener to create (and run) an instance of this monitoring thread, however, this seems pretty much outside Spring.
The second idea was "just" to create a pretty much standard Spring bean which starts (and runs) the CouchDB "watcher" thread either in its constructor or in some method triggered once, in example, by a SimpleTriggerBean.
Looking around, however, I am not sure which of these approaches (if any) is the one I would want to go for, or whether there are more sane ways of dealing with this setup. So, how would you add a feature like this one (a "background" thread starting at context startup and terminating with context shutdown) into your Spring app?
Any input on this greatly welcome. Thanks in advance and all the best,