Hi, all. I have written a v3 module that I'd like to run on startup.
What's the recommended way to do this?
Right now I do this.
import org.glassfish.api.Startup;
import org.jvnet.hk2.annotations.Service;
@Service(name="twibber")
public class Twibber implements Startup, Runnable
{
public Lifecycle getLifecycle() {
return Lifecycle.SERVER;
}
public Twibber() {
new Thread(this).start();
}
public void run() {
// ... Do the actual work here
}
}
It works, but I am concerned it's not the intended approach. What's the
*right* way to run the service? Is it really to spawn the thread in the
constructor? And how do I catch a shutdown event?
I suspect there's something I'm missing...
Thanks,
David