Bug 112646 - Threads aren't shutdown properly when the Platform is shutdown
Summary: Threads aren't shutdown properly when the Platform is shutdown
Status: RESOLVED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: Framework (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.2 M4   Edit
Assignee: equinox.framework-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2005-10-14 11:42 EDT by Simon Kaegi CLA
Modified: 2006-08-23 15:20 EDT (History)
0 users

See Also:


Attachments
Patch to shutdown the daemon threads (3.75 KB, patch)
2005-10-14 16:48 EDT, Simon Kaegi CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Kaegi CLA 2005-10-14 11:42:29 EDT
When the whole platform is shutdown there are still a few active Threads that 
prevent the base Eclipse Classloader from unloading.

The threads I'm referring to are:
1) the optional "State Data Manager" thread in 
org.eclipse.osgi.framework.adaptor.core.StateManager

2) the EventThread(s) created by the 
org.eclipse.osgi.framework.eventmgr.EventManager

In both cases the threads are "setDaemon" so they don't prevent the VM from 
shutting down, however once the platform is shutdown they do not need to be 
active and as I mentioned prevent GC from happening.

--

The "State Data Manager" doesn't currently have a means to shutdown so a patch 
should add this.

The "EventManager" threads do have a shutdown mechanism, it's just a matter of 
using it. The easiest way I can think of doing this is by holding on to the 
org.eclipse.osgi.framework.internal.core.OSGi reference in 
EclipseStarter.startup(...) and calling close() on it during 
EclipseStarter.shutdown().

I can submit a basic patch to show what I'm thinking about.
Comment 1 Simon Kaegi CLA 2005-10-14 16:48:25 EDT
Created attachment 28314 [details]
Patch to shutdown the daemon threads
Comment 2 Thomas Watson CLA 2005-10-20 09:48:33 EDT
Good points.  To make sure I understand the problem.  You want to GC after the 
framework has shutdown and free up all the objects used by the framework 
implementation, right?

The threads mentioned in the bug report are framework threads and should only 
be using classes loaded from the framework implementation.  So GC should be 
possible for objects loaded from other "normal" bundles.  But as mentioned in 
this bug report the deamon threads are staying active and will prevent objects 
from the framework implementation from GC'ing.

We should investigate closing these threads.

- StateSaver#shutdown method should stop the "State Data Manager" thread.
- EclispeStarter should keep a reference to the OSGi object to close when it 
is done with the framework (similar to what the attached patch does).
Comment 3 Simon Kaegi CLA 2005-10-20 12:01:39 EDT
(In reply to comment #2)
> You want to GC after the framework has shutdown and free up all the objects 
used by the framework implementation, right?

Correct.
These threads aren't the only thing preventing GC but they're a step in that 
direction.

Note:
If you _really_ want to see full GC of the platform happen you'll also need the 
patches from bug#107909.




Comment 4 Thomas Watson CLA 2005-10-25 12:26:10 EDT
[contributed patch applied]

- I releases a slightly modified version of the patch to stop the "State Data 
Manager" thread.

- I have not released the patch to stop the threads created by the 
EventManager yet.  I have ongoing work in bug 109893 which fixes this issue.  
If bug 109893 is not fixed for M4 then I will release a fix for the 
EventManager threads separately.  Leaving this bug open until this is resolved.
Comment 5 Thomas Watson CLA 2005-11-15 16:28:57 EST
I released the necessary fixes from bug 109893 to org.eclipse.osgi.  This bug 
should be fixed now.
Comment 6 Thomas Watson CLA 2006-08-23 15:20:15 EDT
adding "contributed" keyword to patches contributed by the community.