You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Paolo28 <pa...@gmail.com> on 2013/09/19 00:48:07 UTC

Re: After camelContext shutdown, is any way to exit the Java main() method?

I have the same problem.

I have not found any solution to this issue. I believe that Camel should be
able to shutdown itself in a graceful manner. My scenario:

1. process N messages (I´m able to detect which is the last)
2. once all messages are processed I want to gracefuly terminate the process
3. depending on the amount of possible errors I need to return non-zero exit
status code 

What I do:

- from a newly spawned thread I stop the initial route and then whole
context using camelContext.stop()
- this new thread dies - it is not hanging
- I´m using 2.11

Result:

- all the "graceful shutdown stuff" is done (I see log messages) but the
process is still running
- I was even able to reliably reproduce weird behaviour: when running with
INFO log level the camel java process exits as expected, however in case
DEBUG log level it continues to run forever
- also trying to connect via JVVM made the hanging process to finish with
exit status=0 which is also a bit weird
- except the "stopping thread" I do not create any of my own threads. 

I spent 2 days with various approaches and so far was not able to reliably
stop Camel application. 
I would prefer some standard way - for example via control bus I would like
to send command to stop everything (there are no more messages anyway). It
seems like Camel in not really designed with this in mind. 









--
View this message in context: http://camel.465427.n5.nabble.com/After-camelContext-shutdown-is-any-way-to-exit-the-Java-main-method-tp5735993p5739792.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: After camelContext shutdown, is any way to exit the Java main() method?

Posted by Paolo28 <pa...@gmail.com>.
Hi,
I´m not calling web service. In my case I had just file poller, splitter
with streaming (line by line processing using Camel Bindy), then aggregator
with parallelProcessing set true. Basically very simple flow. I wanted to
see the threads using JVVM but the JVM connection attempt always resulted in
sudden process terminat ion. 

I´m quite struggling with these lifecycle basics. The thing is that I´m
using Camel for implementing simple batch jobs - not my decision but still
it is convenient as there are many handy components and EIPs. This means I´m
not interested in running Camel as server/service which I can always stop
from operating system environment. How to properly write Main class with
main() method is becoming big excercise :-)
Currently I have working but quite ugly solution. I would like to ask
experienced Camel users how to implement simple 100% SEQUENTIAL and thus
deterministic flow (1-N tasks) where from performance reasons certain stage
or task should be done in parallel (something like
ExecutorService.invokeAll() - i.e. from client/caller perspective it is
synchronous call but behind the scenes the job is done quickly using N
threads). 

The flow is starting using ProducerTemplate - not by any poller etc.
When implementing batch you often need to know when all is done (no more
inflight messages, so you can verify results etc.) and then gracefully exit
the application using either zero or non-zero (errors) exit code.









--
View this message in context: http://camel.465427.n5.nabble.com/After-camelContext-shutdown-is-any-way-to-exit-the-Java-main-method-tp5735993p5739962.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: After camelContext shutdown, is any way to exit the Java main() method?

Posted by SyedBhai <sy...@hotmail.com>.
Hello,  If you are trying to invoke WSDL web service using Camel then this problem is solved I believe.  Kindly search the post titled "Is it Camel Bug?".  A JIRA was filled and the bug was removed.  If you are doing something else then please print the list of current threads in execution.  If one of the threads is started by Camel then that could be another bug in the Camel framework.
Syed.

Date: Wed, 18 Sep 2013 23:01:34 -0700
From: ml-node+s465427n5739807h26@n5.nabble.com
To: syedahmed.csse@hotmail.com
Subject: Re: After camelContext shutdown, is any way to exit the Java main() method?



	Did you try to take a thread dump to see what other threads may be

there to hang. Also mind that if you have non-deamon threads then a

JVM cannot terminate so easily without these threads being terminated

first.




On Thu, Sep 19, 2013 at 12:48 AM, Paolo28 <[hidden email]> wrote:

> I have the same problem.

>

> I have not found any solution to this issue. I believe that Camel should be

> able to shutdown itself in a graceful manner. My scenario:

>

> 1. process N messages (I´m able to detect which is the last)

> 2. once all messages are processed I want to gracefuly terminate the process

> 3. depending on the amount of possible errors I need to return non-zero exit

> status code

>

> What I do:

>

> - from a newly spawned thread I stop the initial route and then whole

> context using camelContext.stop()

> - this new thread dies - it is not hanging

> - I´m using 2.11

>

> Result:

>

> - all the "graceful shutdown stuff" is done (I see log messages) but the

> process is still running

> - I was even able to reliably reproduce weird behaviour: when running with

> INFO log level the camel java process exits as expected, however in case

> DEBUG log level it continues to run forever

> - also trying to connect via JVVM made the hanging process to finish with

> exit status=0 which is also a bit weird

> - except the "stopping thread" I do not create any of my own threads.

>

> I spent 2 days with various approaches and so far was not able to reliably

> stop Camel application.

> I would prefer some standard way - for example via control bus I would like

> to send command to stop everything (there are no more messages anyway). It

> seems like Camel in not really designed with this in mind.

>

>

>

>

>

>

>

>

>

> --

> View this message in context: http://camel.465427.n5.nabble.com/After-camelContext-shutdown-is-any-way-to-exit-the-Java-main-method-tp5735993p5739792.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 

Claus Ibsen

-----------------

Red Hat, Inc.

Email: [hidden email]

Twitter: davsclaus

Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen


	
	
	
	

	

	
	
		If you reply to this email, your message will be added to the discussion below:
		http://camel.465427.n5.nabble.com/After-camelContext-shutdown-is-any-way-to-exit-the-Java-main-method-tp5735993p5739807.html
	
	
		
		To unsubscribe from After camelContext shutdown, is any way to exit the Java main() method?, click here.

		NAML
	 		 	   		  



--
View this message in context: http://camel.465427.n5.nabble.com/After-camelContext-shutdown-is-any-way-to-exit-the-Java-main-method-tp5735993p5739836.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: After camelContext shutdown, is any way to exit the Java main() method?

Posted by Claus Ibsen <cl...@gmail.com>.
Did you try to take a thread dump to see what other threads may be
there to hang. Also mind that if you have non-deamon threads then a
JVM cannot terminate so easily without these threads being terminated
first.



On Thu, Sep 19, 2013 at 12:48 AM, Paolo28 <pa...@gmail.com> wrote:
> I have the same problem.
>
> I have not found any solution to this issue. I believe that Camel should be
> able to shutdown itself in a graceful manner. My scenario:
>
> 1. process N messages (I´m able to detect which is the last)
> 2. once all messages are processed I want to gracefuly terminate the process
> 3. depending on the amount of possible errors I need to return non-zero exit
> status code
>
> What I do:
>
> - from a newly spawned thread I stop the initial route and then whole
> context using camelContext.stop()
> - this new thread dies - it is not hanging
> - I´m using 2.11
>
> Result:
>
> - all the "graceful shutdown stuff" is done (I see log messages) but the
> process is still running
> - I was even able to reliably reproduce weird behaviour: when running with
> INFO log level the camel java process exits as expected, however in case
> DEBUG log level it continues to run forever
> - also trying to connect via JVVM made the hanging process to finish with
> exit status=0 which is also a bit weird
> - except the "stopping thread" I do not create any of my own threads.
>
> I spent 2 days with various approaches and so far was not able to reliably
> stop Camel application.
> I would prefer some standard way - for example via control bus I would like
> to send command to stop everything (there are no more messages anyway). It
> seems like Camel in not really designed with this in mind.
>
>
>
>
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/After-camelContext-shutdown-is-any-way-to-exit-the-Java-main-method-tp5735993p5739792.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen