users@glassfish.java.net

Re: Best practice for a startup module in Glassfish V3

From: Sahoo <Sahoo_at_Sun.COM>
Date: Thu, 04 Sep 2008 13:13:28 +0530

You should do all the heavy lifting in postConstruct method and
implement org.jvnet.hk2.component.PostConstruct interface.

In general, there is an issue about shutting down services when the
server goes down. Jerome was going to address this, not sure what
progress has been made. We need to address it rather quickly.

Why are you not setting daemon status? I hope you plan to start a daemon
thread only, right?

Thanks,
Sahoo

David Van Couvering wrote:
> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>