-
1. Re: Weld SE application lifecycle detecting stop
mkouba Dec 8, 2015 4:19 AM (in response to dermoritz)Hi,
if you're using
ContainerInitialized
then I suppose you're also usingorg.jboss.weld.environment.se.StartMain
to initialize the Weld container and start the application? If so thenContainerShutdown
is the right way to get notification when the container shuts down. However, I'm not really sure about the objectmain
you're calling inside the observer method. When usingStartMain
you should not perform shutdown manually - a shutdown hook is registered automatically by default. You should only care about Weld shutdown if using programmatic bootstrap API. Note that it's also possible to disable the shutdown hook feature completely by using a system property:-Dorg.jboss.weld.se.shutdownHook=false
-
2. Re: Weld SE application lifecycle detecting stop
mkouba Dec 8, 2015 4:22 AM (in response to dermoritz)Also when looking at the stack trace - the ISE is thrown because the Weld container did not manage to initialize itself completely but the application shutdown is already in progress (Weld just attempts to register its own shutdown hook).
-
3. Re: Weld SE application lifecycle detecting stop
dermoritz Dec 8, 2015 9:34 AM (in response to dermoritz)Thanks,
yeas i am using "StartMain". I think the problem is that in my case the method "start(@Observes ContainerInitialized event)" never returns because "main" runs until stopped. And i guess due to this stop is never called. On the other hand weld closes the application as soon as start method has returned (i tried or put main.start() in another thred).
I need to run main.stop() because it waits until all worked has fished (with timeout).
So the question where to put main.start()? So that on the one hand the initialization of weld can be completed but on the other hand weld does not close it self after initialization. Or to put the question the other way around: How to implement a weld se application that runs forever (like a server/service)?
-
4. Re: Weld SE application lifecycle detecting stop
mkouba Dec 8, 2015 10:15 AM (in response to dermoritz)I'm sorry I still don't understand what
main.run()
represents? Anyway, you should never start the Weld container inside a ContainerInitialized observer method - this observer is notified when the container is already being initialized! It would be helpful if you could share your code (or minimal reproducer). If you want to implement a Weld SE application that runs in a loop then you should implement a custom main method, start the Weld container using programmatic bootstrap API and implement some kind of infinite loop (or start a non-daemon thread). -
5. Re: Weld SE application lifecycle detecting stop
dermoritz Dec 9, 2015 4:17 AM (in response to mkouba)just think of main.run() as a never stopping method until someone presses "ctrl-c" (if hangup support is enabled) or someone calls main.stop() (from another thread).
I think the use case to run a never stopping service is not unusual?! Probably it is better to write an own main method and control the container?
-
6. Re: Weld SE application lifecycle detecting stop
mkouba Dec 9, 2015 4:31 AM (in response to dermoritz)Yes, write your own main method. Never implement an infinite loop in a ContainerInitialized observer method otherwise the Weld container initialization never ends!
-
7. Re: Weld SE application lifecycle detecting stop
dermoritz Dec 9, 2015 6:41 AM (in response to mkouba)Thanks, i will do so,
But thismeans that org.jboss.weld.environment.se.StartMain is not usable for service like (never ending) applications? And it means that instantly after container initialization container shutdown is executed?! There is no "container is running" phase (for StartMain) right?
-
8. Re: Weld SE application lifecycle detecting stop
mkouba Dec 9, 2015 7:16 AM (in response to dermoritz)Well, you could start a non-daemon thread (e.g. Swing GUI) in the observer method - in such case the JVM will not stop when
StartMain.main(String[])
completes. -
9. Re: Weld SE application lifecycle detecting stop
dermoritz Dec 11, 2015 5:45 AM (in response to mkouba)Thanks for this tip, i will try both ways (non-deamon thread and own main method)