Question

I have a bundle that is running with infinite loop on Equinox OSGI Framework. Because of this bundle, I am not able to start a new bundle when I run the framework again. How can I stop this bundle in this situation?

Here is the command I type to start the framework:

java -jar org.eclipse.osgi_3.9.0.v20130529-1710.jar -console

It shows this message infinitely:

Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
...........

Answering this question will also help to answer how to stop an OSGI bundle while it is executing a method, and if that is allowed or not.

Was it helpful?

Solution

I assume that your bundle has entered an infinite loop in its BundleActivator.start method, and therefore tied up the OSGi callback. Obviously this is not something you should do!! You have no choice but to shutdown the JVM, perhaps forcibly.

Now the problem is to stop the bundle from being started again automatically next time you launch OSGi. The simplest way to ensure this is to delete the "storage" directory where OSGi remembers the list of bundles that were started last time it ran. Unfortunately the storage directory location is subject to a configuration property and you have not specified how you have configured OSGi. The default for Equinox is configuration/org.eclipse.osgi, so try deleting that. You could also try running with -clean.

Regarding how to stop an OSGi bundle while it is executing a method: you can of course stop a bundle and this will cause its stop method to execute. You can do whatever you like in that method: in general you should aim to clean up anything you created in the start method. However if you have a runaway thread then there is basically nothing you can do, since Java offers no way to kill a thread, it only offers a cooperative interrupt method.

OSGi cannot change the fundamental rules of Java, so runaway threads are just as much of a problem in OSGi as they are in any other Java application.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top