I have a Java SE application with the CDI / Weld ( org.jboss.weld.environment.se StartMain , without any application server)
I have tried to create a @Singleton Bean which looks at the container-infraised event (like below) but I'm not sure when the container This service will destroy the bean. Is this safe? Is there a better way?
@Singleton public square background service {Start at public zero (@ Observe Container Initial Event) {// Other Threads Getting Started}}
I will personally use @spop not @Singleton . When the container is closed, the lifecycle will close the object. If you want to start a thread, then it will be a possible option for inserting this code.
It is not asynchronous by default, so you have to start your thread.
Comments
Post a Comment