I don't know if it's ok according to the spec, but you can also write a ServletContextInitialized that starts a thread in the init method and kills it in the destroy method. It worked for me at least. If portability is not critical you can also write a Glassfish lifecycle module that starts a thread. Note that the ServletContextInitializer (which is deployed as a web application) can be redeployed without restarting Glassfish, which is not possible with a lifecycle. Of course, if you have a clustered Glassfish, then these simple solutions may not work (each node will have its background thread)
[Message sent by forum member 'ewernli' (ewernli)]
http://forums.java.net/jive/thread.jspa?messageID=253860