If you can use the EJB
with(or instead of) CDI
, then try the @Singleton
+ @Startup
annotations for your bean, and @PostConstruct
for your main()
method.
@Singleton
@Startup
public class YourBean {
@Stateless
public static class BeanWithMainMethod{
@Asynchronous
public void theMainMethod(){
System.out.println("Async invocation");
}
}
@EJB
private BeanWithMainMethod beanWithMainMethod;
@PostConstruct
private void launchMainMethod(){
beanWithMainMethod.theMainMethod();
}
}