If Eclipse hangs when it tries to load your plug-in and if you see something like this in your error log:
thread "Thread [main,6,main]" timed out waiting (5000ms) for thread
"Thread [Worker-3,5,main]" to finish
then you’re probably interested in this post.
This is a somewhat known Eclipse bug and you can find more information about it here.
The problem is best described by Thomas Watson in Comment #4 in the Eclipse bug report.
The bottom line is that you should avoid doing heavy work in your plug-in start() method and instead defer the execution of any plug-in initialization code until you’re sure that the plug-in has been successfully resolved. Why? As Thomas points out, this ensures that the plug-in does not need to load any classes before it is initialized, which seems to be to root cause of the thread deadlock problem (one thread tries to initialized the plug-in and another thread tries to load a need class - but they both wait for the other to finish).
So to essentially dig yourself out of such a situation you need to listen for bundle event. To make this clearer, let’s look at an example. Let’s say your plug-in start() method looks something like this:
public void start(BundleContext context) throws Exception {
super.start(context);
myPluginInitialization();
}
If you’re trying to load classes from within your plug-in in myPluginInitialization(), then what you need to do is have your plug-in implement org.osgi.framework.SynchronousBundleListener, replace the myPluginInitialization() call from start() with context.addBundleListener(this), and implement the bundleChanged(BundleEvent event) method from SynchronousBundleListener as follows:
Bundle bundle = event.getBundle();
if (!bundle.equals(getBundle()))
return;
int type = event.getType();
switch (type) {
case BundleEvent.RESOLVED:
myPluginInitialization();
break;
}
Leave a Reply
You must be logged in to post a comment.