You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by selezovikj <se...@gmail.com> on 2009/02/13 10:57:16 UTC

Starting camel from my own class - Camel stops when main method stops

I want to start Camel from my own class called Startup because I want to
start other services as well. 
In the Startup class I do the following: 

// org.apache.camel.spring.Main
Main camelMain = new Main();
camelMain.setApplicationContextUri("../config/jms-routing.xml");

try {
            camelMain.start();
            
        } catch (Exception e) {
            
            logger.error("Error starting camel", e);
            System.exit(-1);
        }

Once the main method exits camel is stopped as well: 

2009-02-13 10:40:03,509 [                          main] TransportConnector            
INFO  Connector tcp Started
2009-02-13 10:40:03,510 [                          main] BrokerService                 
INFO  ActiveMQ JMS Message Broker (localhost,
ID:semir.2e-systems.com-58933-1234518003268-0:0) started
2009-02-13 10:40:08,824 [         ActiveMQ ShutdownHook] BrokerService                 
INFO  ActiveMQ Message Broker (localhost,
ID:semir.2e-systems.com-58933-1234518003268-0:0) is shutting down
2009-02-13 10:40:09,512 [         ActiveMQ ShutdownHook] TransportConnector            
INFO  Connector tcp Stopped
2009-02-13 10:40:09,578 [         ActiveMQ ShutdownHook] BrokerService                 
INFO  ActiveMQ JMS Message Broker (localhost,
ID:semir.2e-systems.com-58933-1234518003268-0:0) stopped


If I put a thread sleep before the main method exits for 20 seconds ... then
Camel is up on 61617 for around 20 seconds. 

Am I doing something wrong ? 
Can anybody help ? 

-- 
View this message in context: http://www.nabble.com/Starting-camel-from-my-own-class---Camel-stops-when-main-method-stops-tp21993387s22882p21993387.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Starting camel from my own class - Camel stops when main method stops

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

And maybe this page can also help setting some lower timeouts on the JMS
http://activemq.apache.org/tcp-transport-reference.html


On Sat, Feb 14, 2009 at 8:23 AM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> You can use ctrl + break or ctrl + \ on unix to dump the thread list
> when you app hangs.
> You can then identify what happens
>
> We fixed an issue with the Main app not being able to stop properly,
> that is fixed in Camel 1.6.0,
> with a thread waiting for a countdown latch.
>
> So try out the 1.6.0 when its released
>
> On Fri, Feb 13, 2009 at 5:47 PM, James Strachan
> <ja...@gmail.com> wrote:
>> This looks like its down to daemon threads (I can never remember
>> whether daemon on or off stops the JVM from terminating :).
>>
>> The easiest way to fix it might be having a loop in your main asking
>> the user to enter 'quit' to terminate the application or something.
>>
>> Either that or just wait forever via an infinite loop...
>>
>> Object lock = new Object();
>> while (true) {
>>  synchronized { try { lock.wait(); } catch (Exception e) { } }
>> }
>>
>>
>> 2009/2/13 selezovikj <se...@gmail.com>:
>>>
>>> I want to start Camel from my own class called Startup because I want to
>>> start other services as well.
>>> In the Startup class I do the following:
>>>
>>> // org.apache.camel.spring.Main
>>> Main camelMain = new Main();
>>> camelMain.setApplicationContextUri("../config/jms-routing.xml");
>>>
>>> try {
>>>            camelMain.start();
>>>
>>>        } catch (Exception e) {
>>>
>>>            logger.error("Error starting camel", e);
>>>            System.exit(-1);
>>>        }
>>>
>>> Once the main method exits camel is stopped as well:
>>>
>>> 2009-02-13 10:40:03,509 [                          main] TransportConnector
>>> INFO  Connector tcp Started
>>> 2009-02-13 10:40:03,510 [                          main] BrokerService
>>> INFO  ActiveMQ JMS Message Broker (localhost,
>>> ID:semir.2e-systems.com-58933-1234518003268-0:0) started
>>> 2009-02-13 10:40:08,824 [         ActiveMQ ShutdownHook] BrokerService
>>> INFO  ActiveMQ Message Broker (localhost,
>>> ID:semir.2e-systems.com-58933-1234518003268-0:0) is shutting down
>>> 2009-02-13 10:40:09,512 [         ActiveMQ ShutdownHook] TransportConnector
>>> INFO  Connector tcp Stopped
>>> 2009-02-13 10:40:09,578 [         ActiveMQ ShutdownHook] BrokerService
>>> INFO  ActiveMQ JMS Message Broker (localhost,
>>> ID:semir.2e-systems.com-58933-1234518003268-0:0) stopped
>>>
>>>
>>> If I put a thread sleep before the main method exits for 20 seconds ... then
>>> Camel is up on 61617 for around 20 seconds.
>>>
>>> Am I doing something wrong ?
>>> Can anybody help ?
>>>
>>> --
>>> View this message in context: http://www.nabble.com/Starting-camel-from-my-own-class---Camel-stops-when-main-method-stops-tp21993387s22882p21993387.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>>
>> --
>> James
>> -------
>> http://macstrac.blogspot.com/
>>
>> Open Source Integration
>> http://fusesource.com/
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/

Re: Starting camel from my own class - Camel stops when main method stops

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You can use ctrl + break or ctrl + \ on unix to dump the thread list
when you app hangs.
You can then identify what happens

We fixed an issue with the Main app not being able to stop properly,
that is fixed in Camel 1.6.0,
with a thread waiting for a countdown latch.

So try out the 1.6.0 when its released

On Fri, Feb 13, 2009 at 5:47 PM, James Strachan
<ja...@gmail.com> wrote:
> This looks like its down to daemon threads (I can never remember
> whether daemon on or off stops the JVM from terminating :).
>
> The easiest way to fix it might be having a loop in your main asking
> the user to enter 'quit' to terminate the application or something.
>
> Either that or just wait forever via an infinite loop...
>
> Object lock = new Object();
> while (true) {
>  synchronized { try { lock.wait(); } catch (Exception e) { } }
> }
>
>
> 2009/2/13 selezovikj <se...@gmail.com>:
>>
>> I want to start Camel from my own class called Startup because I want to
>> start other services as well.
>> In the Startup class I do the following:
>>
>> // org.apache.camel.spring.Main
>> Main camelMain = new Main();
>> camelMain.setApplicationContextUri("../config/jms-routing.xml");
>>
>> try {
>>            camelMain.start();
>>
>>        } catch (Exception e) {
>>
>>            logger.error("Error starting camel", e);
>>            System.exit(-1);
>>        }
>>
>> Once the main method exits camel is stopped as well:
>>
>> 2009-02-13 10:40:03,509 [                          main] TransportConnector
>> INFO  Connector tcp Started
>> 2009-02-13 10:40:03,510 [                          main] BrokerService
>> INFO  ActiveMQ JMS Message Broker (localhost,
>> ID:semir.2e-systems.com-58933-1234518003268-0:0) started
>> 2009-02-13 10:40:08,824 [         ActiveMQ ShutdownHook] BrokerService
>> INFO  ActiveMQ Message Broker (localhost,
>> ID:semir.2e-systems.com-58933-1234518003268-0:0) is shutting down
>> 2009-02-13 10:40:09,512 [         ActiveMQ ShutdownHook] TransportConnector
>> INFO  Connector tcp Stopped
>> 2009-02-13 10:40:09,578 [         ActiveMQ ShutdownHook] BrokerService
>> INFO  ActiveMQ JMS Message Broker (localhost,
>> ID:semir.2e-systems.com-58933-1234518003268-0:0) stopped
>>
>>
>> If I put a thread sleep before the main method exits for 20 seconds ... then
>> Camel is up on 61617 for around 20 seconds.
>>
>> Am I doing something wrong ?
>> Can anybody help ?
>>
>> --
>> View this message in context: http://www.nabble.com/Starting-camel-from-my-own-class---Camel-stops-when-main-method-stops-tp21993387s22882p21993387.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>
>
>
> --
> James
> -------
> http://macstrac.blogspot.com/
>
> Open Source Integration
> http://fusesource.com/
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/

Re: Starting camel from my own class - Camel stops when main method stops

Posted by James Strachan <ja...@gmail.com>.
This looks like its down to daemon threads (I can never remember
whether daemon on or off stops the JVM from terminating :).

The easiest way to fix it might be having a loop in your main asking
the user to enter 'quit' to terminate the application or something.

Either that or just wait forever via an infinite loop...

Object lock = new Object();
while (true) {
  synchronized { try { lock.wait(); } catch (Exception e) { } }
}


2009/2/13 selezovikj <se...@gmail.com>:
>
> I want to start Camel from my own class called Startup because I want to
> start other services as well.
> In the Startup class I do the following:
>
> // org.apache.camel.spring.Main
> Main camelMain = new Main();
> camelMain.setApplicationContextUri("../config/jms-routing.xml");
>
> try {
>            camelMain.start();
>
>        } catch (Exception e) {
>
>            logger.error("Error starting camel", e);
>            System.exit(-1);
>        }
>
> Once the main method exits camel is stopped as well:
>
> 2009-02-13 10:40:03,509 [                          main] TransportConnector
> INFO  Connector tcp Started
> 2009-02-13 10:40:03,510 [                          main] BrokerService
> INFO  ActiveMQ JMS Message Broker (localhost,
> ID:semir.2e-systems.com-58933-1234518003268-0:0) started
> 2009-02-13 10:40:08,824 [         ActiveMQ ShutdownHook] BrokerService
> INFO  ActiveMQ Message Broker (localhost,
> ID:semir.2e-systems.com-58933-1234518003268-0:0) is shutting down
> 2009-02-13 10:40:09,512 [         ActiveMQ ShutdownHook] TransportConnector
> INFO  Connector tcp Stopped
> 2009-02-13 10:40:09,578 [         ActiveMQ ShutdownHook] BrokerService
> INFO  ActiveMQ JMS Message Broker (localhost,
> ID:semir.2e-systems.com-58933-1234518003268-0:0) stopped
>
>
> If I put a thread sleep before the main method exits for 20 seconds ... then
> Camel is up on 61617 for around 20 seconds.
>
> Am I doing something wrong ?
> Can anybody help ?
>
> --
> View this message in context: http://www.nabble.com/Starting-camel-from-my-own-class---Camel-stops-when-main-method-stops-tp21993387s22882p21993387.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://fusesource.com/