Thread execution - Java EE - Jboss

4

I have a web application using Jboss EAP, JSF, CDI, EJB and need to start a thread whenever JBoss is started.

The thread belongs to the TinyRadius package that implements a Radius server. How can I invoke the start method every time I start the application?

    
asked by anonymous 03.10.2015 / 03:28

1 answer

2

There are a few ways to do this, such as using ServletContextListener , startup servlets (see load-on-startup in the specification ), resource adapters in full profile environments , EJB 3.1 @Startup , etc.

The decision of which to use varies from design to design and from the various most common approaches are these:

@WebListener
public class YourStartupApplication implements ServletContextListener {

    @Inject
    private Service service;

    @Override
    public void contextInitialized(final ServletContextEvent sce)  { 
         service.doSomethingOnStartup();
    }

    @Override
    public void contextDestroyed(final ServletContextEvent sce)  {
         service.doSomethingOnShutdown();    
    }

}
@Startup
@Singleton
public class YourStartupApplication {

    @Inject
    private Service service;

    @PostConstruct
    public void startup()  { 
         service.doSomethingOnStartup();
    }

    @PreDestroy
    public void shutdown()  {
         service.doSomethingOnShutdown();    
    }

}
    
03.10.2015 / 16:31