You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Damian Minkov <da...@sip-communicator.org> on 2010/09/16 13:01:46 UTC

Stopping and non daemon threads

Hi,

I'm currently looking at a problem in sip-communicator on shutting
down. To shut down we stop bundle with id 0. But in some of our
bundles we need to do some stuff which involves network operations,
and so we create a non daemon Thread in order to do it. But just a
little after the Thread is created and started the application exits
and don't finish all the operations.
Any ideas why this happen or just am I missing some configuration?

Thanks
damencho

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Stopping and non daemon threads

Posted by "Richard S. Hall" <he...@ungoverned.org>.
  On 9/16/10 4:01, Damian Minkov wrote:
> Hi,
>
> I'm currently looking at a problem in sip-communicator on shutting
> down. To shut down we stop bundle with id 0. But in some of our
> bundles we need to do some stuff which involves network operations,
> and so we create a non daemon Thread in order to do it. But just a
> little after the Thread is created and started the application exits
> and don't finish all the operations.
> Any ideas why this happen or just am I missing some configuration?

The Felix framework never calls System.exit()...if you are using the 
Felix launcher, it will call System.exit() after the framework 
successfully stops. There is no way to disable that.

-> richard

> Thanks
> damencho
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Stopping and non daemon threads

Posted by Will Budic <vi...@gmail.com>.
Daemon threads are not waited for hence their usefulness if they are to do
trivial background processing while the normal main thread is working.

On 16 September 2010 21:01, Damian Minkov <da...@sip-communicator.org>wrote:

> Hi,
>
> I'm currently looking at a problem in sip-communicator on shutting
> down. To shut down we stop bundle with id 0. But in some of our
> bundles we need to do some stuff which involves network operations,
> and so we create a non daemon Thread in order to do it. But just a
> little after the Thread is created and started the application exits
> and don't finish all the operations.
> Any ideas why this happen or just am I missing some configuration?
>
> Thanks
> damencho
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>

Re: Stopping and non daemon threads

Posted by Michael Hess <MH...@orga-systems.com>.
> > Well, the JVM can of course only exit after all non-daemon threads 
have
> > been stopped or after a call to System.exit(int).
> Yes the problem is that we are not calling System.exit and even that
> non-daemon thread is created the JVM exit without waiting it.

Just a shot in the dark, but did you check the output of that thread of 
yours? Since the system is shutting down it might be, that your Thread 
simply fails to do its work (e.g. due to a missing service or something) 
and bails out early. If your thread dies, then it would make sense that 
you see your described behavior.

bye, Michael

OT: Please check your mailer settings. It seems you are spamming the list, 
as each of your emails arrives here numerous times. (or is this just me?)

The information included in this e-mail and any files transmitted with it is strictly confidential and may be privileged or otherwise protected from disclosure. If you are not the intended recipient, please notify the sender immediately by e-mail and delete this e-mail as well as any attachment from your system. If you are not the intended recipient you are not authorized to use and/or copy this message and/or attachment and/or disclose the contents to any other person.

Re: Stopping and non daemon threads

Posted by Damian Minkov <da...@sip-communicator.org>.
Hi,

On Thu, Sep 16, 2010 at 2:39 PM, Felix Meschberger <fm...@gmail.com> wrote:
> Hi,
>
> Well, the JVM can of course only exit after all non-daemon threads have
> been stopped or after a call to System.exit(int).
Yes the problem is that we are not calling System.exit and even that
non-daemon thread is created the JVM exit without waiting it.

>
> Now, if you have a bundle which starts a thread, you must make sure to
> stop that thread when the bundle stopped. Otherwise you create a memory
> and performance leak if the bundle is repeatedly started, stopped,
> updated etc.
Yes we have take care of this we even have another shutdown thread
monitoring this and if something is stuck after a timeout forces
everything by calling System.exit.

Regards
damencho

>
> Regards
> Felix
>
> Am 16.09.2010 13:01, schrieb Damian Minkov:
>> Hi,
>>
>> I'm currently looking at a problem in sip-communicator on shutting
>> down. To shut down we stop bundle with id 0. But in some of our
>> bundles we need to do some stuff which involves network operations,
>> and so we create a non daemon Thread in order to do it. But just a
>> little after the Thread is created and started the application exits
>> and don't finish all the operations.
>> Any ideas why this happen or just am I missing some configuration?
>>
>> Thanks
>> damencho
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Stopping and non daemon threads

Posted by Damian Minkov <da...@sip-communicator.org>.
Hi,

I see, thanks for pointing it, but what about the ShutdownHook isn't
it there to prevent such behaviour and to wait for stopping....
Aha I see it while I'm writing :) the ShutdownHook just waits the
bundles to be stopped and there are stopped and its different from
ending all threads created by the bundles and so the Main ends and
calls System.exit.

Thanks once again for pointing it
damencho

On Thu, Sep 16, 2010 at 5:39 PM, Karl Pauls <ka...@gmail.com> wrote:
> Are you maybe using just the normal Main method of the main bundle? In
> that case, we do call system exit in there after the framework is
> shutdown:
>
> http://svn.apache.org/repos/asf/felix/trunk/main/src/main/java/org/apache/felix/main/Main.java
>
> regards,
>
> Karl
>
> On Thu, Sep 16, 2010 at 3:51 PM, Damian Minkov
> <da...@sip-communicator.org> wrote:
>> Hi all,
>>
>> thank you all for the suggestions, I was checking them but without any
>> change. So I made a simple test case that reflects our behaviour. Find
>> it attached.
>>
>> The example just starts felix, then one bundle is started which waits
>> for 2 seconds then calls the stopping the same way we do and when
>> bundle stop method is called it creates a non daemon Thread which will
>> wait for 5 seconds. The whole execution must take at least 8 seconds.
>> But it takes no more then 3 or 4(including ant tartgets).
>> Here is the output of one execution:
>> run:
>>
>>     [java] Now wait 3 sec.
>>     [java] start the felix stopping
>>     [java] Stopped!
>>     [java] Now wait 5 sec. before end
>>
>> BUILD SUCCESSFUL
>> Total time: 3 seconds
>>
>> To run it just place felix Main jar in lib folder and do "ant run"
>> (I've tested with org.apache.felix.main-3.0.2.jar).
>>
>> Thanks
>> damencho
>>
>>
>> On Thu, Sep 16, 2010 at 3:13 PM, peter lawrey <pe...@edgeci.com> wrote:
>>> The JVM will also die if it crashes.  E.g. you might have a JNI library you are using and it has a bug in its shutdown/unload.  Have a look for a hs_err_pid*.log file in the working directory of your instance.
>>>
>>> Otherwise, you really are calling System.exit() if not directly. In which case you should be able to debug your instance and breakpoint this call to see if it being called.
>>>
>>> AFAIK, Even if all your thread are daemons, felix has threads which are not so this is unlikely to be the cause of your problem.
>>>
>>> -----Original Message-----
>>> From: Felix Meschberger [mailto:fmeschbe@gmail.com]
>>> Sent: 16 September 2010 12:40
>>> To: users@felix.apache.org
>>> Subject: Re: Stopping and non daemon threads
>>>
>>> Hi,
>>>
>>> Well, the JVM can of course only exit after all non-daemon threads have
>>> been stopped or after a call to System.exit(int).
>>>
>>> Now, if you have a bundle which starts a thread, you must make sure to
>>> stop that thread when the bundle stopped. Otherwise you create a memory
>>> and performance leak if the bundle is repeatedly started, stopped,
>>> updated etc.
>>>
>>> Regards
>>> Felix
>>>
>>> Am 16.09.2010 13:01, schrieb Damian Minkov:
>>>> Hi,
>>>>
>>>> I'm currently looking at a problem in sip-communicator on shutting
>>>> down. To shut down we stop bundle with id 0. But in some of our
>>>> bundles we need to do some stuff which involves network operations,
>>>> and so we create a non daemon Thread in order to do it. But just a
>>>> little after the Thread is created and started the application exits
>>>> and don't finish all the operations.
>>>> Any ideas why this happen or just am I missing some configuration?
>>>>
>>>> Thanks
>>>> damencho
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>>> For additional commands, e-mail: users-help@felix.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>> For additional commands, e-mail: users-help@felix.apache.org
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>
>
>
> --
> Karl Pauls
> karlpauls@gmail.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Stopping and non daemon threads

Posted by Karl Pauls <ka...@gmail.com>.
Are you maybe using just the normal Main method of the main bundle? In
that case, we do call system exit in there after the framework is
shutdown:

http://svn.apache.org/repos/asf/felix/trunk/main/src/main/java/org/apache/felix/main/Main.java

regards,

Karl

On Thu, Sep 16, 2010 at 3:51 PM, Damian Minkov
<da...@sip-communicator.org> wrote:
> Hi all,
>
> thank you all for the suggestions, I was checking them but without any
> change. So I made a simple test case that reflects our behaviour. Find
> it attached.
>
> The example just starts felix, then one bundle is started which waits
> for 2 seconds then calls the stopping the same way we do and when
> bundle stop method is called it creates a non daemon Thread which will
> wait for 5 seconds. The whole execution must take at least 8 seconds.
> But it takes no more then 3 or 4(including ant tartgets).
> Here is the output of one execution:
> run:
>
>     [java] Now wait 3 sec.
>     [java] start the felix stopping
>     [java] Stopped!
>     [java] Now wait 5 sec. before end
>
> BUILD SUCCESSFUL
> Total time: 3 seconds
>
> To run it just place felix Main jar in lib folder and do "ant run"
> (I've tested with org.apache.felix.main-3.0.2.jar).
>
> Thanks
> damencho
>
>
> On Thu, Sep 16, 2010 at 3:13 PM, peter lawrey <pe...@edgeci.com> wrote:
>> The JVM will also die if it crashes.  E.g. you might have a JNI library you are using and it has a bug in its shutdown/unload.  Have a look for a hs_err_pid*.log file in the working directory of your instance.
>>
>> Otherwise, you really are calling System.exit() if not directly. In which case you should be able to debug your instance and breakpoint this call to see if it being called.
>>
>> AFAIK, Even if all your thread are daemons, felix has threads which are not so this is unlikely to be the cause of your problem.
>>
>> -----Original Message-----
>> From: Felix Meschberger [mailto:fmeschbe@gmail.com]
>> Sent: 16 September 2010 12:40
>> To: users@felix.apache.org
>> Subject: Re: Stopping and non daemon threads
>>
>> Hi,
>>
>> Well, the JVM can of course only exit after all non-daemon threads have
>> been stopped or after a call to System.exit(int).
>>
>> Now, if you have a bundle which starts a thread, you must make sure to
>> stop that thread when the bundle stopped. Otherwise you create a memory
>> and performance leak if the bundle is repeatedly started, stopped,
>> updated etc.
>>
>> Regards
>> Felix
>>
>> Am 16.09.2010 13:01, schrieb Damian Minkov:
>>> Hi,
>>>
>>> I'm currently looking at a problem in sip-communicator on shutting
>>> down. To shut down we stop bundle with id 0. But in some of our
>>> bundles we need to do some stuff which involves network operations,
>>> and so we create a non daemon Thread in order to do it. But just a
>>> little after the Thread is created and started the application exits
>>> and don't finish all the operations.
>>> Any ideas why this happen or just am I missing some configuration?
>>>
>>> Thanks
>>> damencho
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>> For additional commands, e-mail: users-help@felix.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>



-- 
Karl Pauls
karlpauls@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Stopping and non daemon threads

Posted by Damian Minkov <da...@sip-communicator.org>.
Hi all,

thank you all for the suggestions, I was checking them but without any
change. So I made a simple test case that reflects our behaviour. Find
it attached.

The example just starts felix, then one bundle is started which waits
for 2 seconds then calls the stopping the same way we do and when
bundle stop method is called it creates a non daemon Thread which will
wait for 5 seconds. The whole execution must take at least 8 seconds.
But it takes no more then 3 or 4(including ant tartgets).
Here is the output of one execution:
run:

     [java] Now wait 3 sec.
     [java] start the felix stopping
     [java] Stopped!
     [java] Now wait 5 sec. before end

BUILD SUCCESSFUL
Total time: 3 seconds

To run it just place felix Main jar in lib folder and do "ant run"
(I've tested with org.apache.felix.main-3.0.2.jar).

Thanks
damencho


On Thu, Sep 16, 2010 at 3:13 PM, peter lawrey <pe...@edgeci.com> wrote:
> The JVM will also die if it crashes.  E.g. you might have a JNI library you are using and it has a bug in its shutdown/unload.  Have a look for a hs_err_pid*.log file in the working directory of your instance.
>
> Otherwise, you really are calling System.exit() if not directly. In which case you should be able to debug your instance and breakpoint this call to see if it being called.
>
> AFAIK, Even if all your thread are daemons, felix has threads which are not so this is unlikely to be the cause of your problem.
>
> -----Original Message-----
> From: Felix Meschberger [mailto:fmeschbe@gmail.com]
> Sent: 16 September 2010 12:40
> To: users@felix.apache.org
> Subject: Re: Stopping and non daemon threads
>
> Hi,
>
> Well, the JVM can of course only exit after all non-daemon threads have
> been stopped or after a call to System.exit(int).
>
> Now, if you have a bundle which starts a thread, you must make sure to
> stop that thread when the bundle stopped. Otherwise you create a memory
> and performance leak if the bundle is repeatedly started, stopped,
> updated etc.
>
> Regards
> Felix
>
> Am 16.09.2010 13:01, schrieb Damian Minkov:
>> Hi,
>>
>> I'm currently looking at a problem in sip-communicator on shutting
>> down. To shut down we stop bundle with id 0. But in some of our
>> bundles we need to do some stuff which involves network operations,
>> and so we create a non daemon Thread in order to do it. But just a
>> little after the Thread is created and started the application exits
>> and don't finish all the operations.
>> Any ideas why this happen or just am I missing some configuration?
>>
>> Thanks
>> damencho
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>

RE: Stopping and non daemon threads

Posted by peter lawrey <pe...@edgeci.com>.
The JVM will also die if it crashes.  E.g. you might have a JNI library you are using and it has a bug in its shutdown/unload.  Have a look for a hs_err_pid*.log file in the working directory of your instance.

Otherwise, you really are calling System.exit() if not directly. In which case you should be able to debug your instance and breakpoint this call to see if it being called.

AFAIK, Even if all your thread are daemons, felix has threads which are not so this is unlikely to be the cause of your problem.

-----Original Message-----
From: Felix Meschberger [mailto:fmeschbe@gmail.com] 
Sent: 16 September 2010 12:40
To: users@felix.apache.org
Subject: Re: Stopping and non daemon threads

Hi,

Well, the JVM can of course only exit after all non-daemon threads have
been stopped or after a call to System.exit(int).

Now, if you have a bundle which starts a thread, you must make sure to
stop that thread when the bundle stopped. Otherwise you create a memory
and performance leak if the bundle is repeatedly started, stopped,
updated etc.

Regards
Felix

Am 16.09.2010 13:01, schrieb Damian Minkov:
> Hi,
> 
> I'm currently looking at a problem in sip-communicator on shutting
> down. To shut down we stop bundle with id 0. But in some of our
> bundles we need to do some stuff which involves network operations,
> and so we create a non daemon Thread in order to do it. But just a
> little after the Thread is created and started the application exits
> and don't finish all the operations.
> Any ideas why this happen or just am I missing some configuration?
> 
> Thanks
> damencho
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Stopping and non daemon threads

Posted by Felix Meschberger <fm...@gmail.com>.
Hi,

Well, the JVM can of course only exit after all non-daemon threads have
been stopped or after a call to System.exit(int).

Now, if you have a bundle which starts a thread, you must make sure to
stop that thread when the bundle stopped. Otherwise you create a memory
and performance leak if the bundle is repeatedly started, stopped,
updated etc.

Regards
Felix

Am 16.09.2010 13:01, schrieb Damian Minkov:
> Hi,
> 
> I'm currently looking at a problem in sip-communicator on shutting
> down. To shut down we stop bundle with id 0. But in some of our
> bundles we need to do some stuff which involves network operations,
> and so we create a non daemon Thread in order to do it. But just a
> little after the Thread is created and started the application exits
> and don't finish all the operations.
> Any ideas why this happen or just am I missing some configuration?
> 
> Thanks
> damencho
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Stopping and non daemon threads

Posted by "Richard S. Hall" <he...@ungoverned.org>.
  If you really want to wait for the operation to complete, then you 
shouldn't be doing it on a separate thread. Just do it in your activator 
stop() method with the calling thread or have the calling thread wait 
for your other thread.

-> richard

On 9/16/10 4:22, Christopher Brind wrote:
> I believe the standard Felix launcher calls System.exit after the framework
> bundle stops, which of course does not care if there are non-daemon threads
> or otherwise.
>
> See this page for info:
> http://felix.apache.org/site/apache-felix-framework-launching-and-embedding.html
>
> You could create a custom launcher or create a controller bundle which is
> responsible for shutting down the framework by calling stop on the bundles
> that need time to shutdown gracefully and then when they're finished calls
> shutdown on bundle 0 as normal.
>
> I'd probably go with the latter as you might not be sure what other bundles
> are creating non-daemon threads which will prevent your container from
> shutting down at all.
>
> Cheers,
> Chris
>
>
>
> On 16 September 2010 12:01, Damian Minkov<da...@sip-communicator.org>wrote:
>
>> Hi,
>>
>> I'm currently looking at a problem in sip-communicator on shutting
>> down. To shut down we stop bundle with id 0. But in some of our
>> bundles we need to do some stuff which involves network operations,
>> and so we create a non daemon Thread in order to do it. But just a
>> little after the Thread is created and started the application exits
>> and don't finish all the operations.
>> Any ideas why this happen or just am I missing some configuration?
>>
>> Thanks
>> damencho
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Stopping and non daemon threads

Posted by Christopher Brind <br...@brindy.org.uk>.
I believe the standard Felix launcher calls System.exit after the framework
bundle stops, which of course does not care if there are non-daemon threads
or otherwise.

See this page for info:
http://felix.apache.org/site/apache-felix-framework-launching-and-embedding.html

You could create a custom launcher or create a controller bundle which is
responsible for shutting down the framework by calling stop on the bundles
that need time to shutdown gracefully and then when they're finished calls
shutdown on bundle 0 as normal.

I'd probably go with the latter as you might not be sure what other bundles
are creating non-daemon threads which will prevent your container from
shutting down at all.

Cheers,
Chris



On 16 September 2010 12:01, Damian Minkov <da...@sip-communicator.org>wrote:

> Hi,
>
> I'm currently looking at a problem in sip-communicator on shutting
> down. To shut down we stop bundle with id 0. But in some of our
> bundles we need to do some stuff which involves network operations,
> and so we create a non daemon Thread in order to do it. But just a
> little after the Thread is created and started the application exits
> and don't finish all the operations.
> Any ideas why this happen or just am I missing some configuration?
>
> Thanks
> damencho
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>