|Re: [equinox-dev] Simple SWT App launched with OSGi Launcher hangs on Mac OS X|
The issue is on Mac the SWT event loop must run on the main thread. That is a pretty hard thing to do in an OSGi environment. When a bundle is activated it has no idea what thread is activating it. Even if the bundle knew the activating thread was the main thread it would never want to actually run the SWT event loop in the BundleActivator.start method because that would hang the Bundle.start() operation. Instead the bundle should spawn a separate thread to run the SWT event loop, but that thread will not be the main thread so SWT will fail to work on Mac.
In Eclipse we have the notion of an Eclipse Application which are defined by an extension to the org.eclipse.core.runtime.applications extension point. By default Eclipse Applications are run on the main thread. This is accomplished by the boot strap code (EclipseStarter) which has access to the main thread and waits for an application to be launched. This is the sample RCP application works on Mac. When using the -Declipse.ignoreApp=true option you are telling the bootstrap code to forget about launching an eclipse application on the main thread which allows the main thread to completely go away.
You have two options
1) Install the application model from eclipse. This includes 3 bundles (org.eclipse.equinox.common, org.eclipse.equinox.registry, org.eclipse.equinox.app). Then create an extension to org.eclipse.equinox.app and implement IApplication. In IApplication.start you can start the SWT event loop. You would add the three extra bundles to your osgi.bundles list and be sure to start the org.eclipse.equinox.app bundle. Also be sure to not use the eclipse.ignoreApp=true option.
You also need to tell the application model about your application with the program argument -application <your app extension id>
2) Use the org.eclipse.osgi.service.runnable.ApplicationLauncher service published by EclipseStarter (when not using eclipse.ignoreApp=true) to run the SWT event loop on the main thread. This is the same way the Eclipse Application model launches things on the main thread.
Patrick Dempsey ---08/30/2007 02:44:36 PM---I have a very simple SWT sample bundle (attached). It has both a main and a bundle activator so it can be run stand-alone or u
Sent by: equinox-dev-bounces@xxxxxxxxxxx
08/30/2007 02:44 PM