Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Deadlock while calling "Toolkit.getDefaultToolkit()" in an OSGi environment
Deadlock while calling "Toolkit.getDefaultToolkit()" in an OSGi environment [message #526602] Mon, 12 April 2010 12:07 Go to next message
Simon Eiersbrock is currently offline Simon Eiersbrock
Messages: 2
Registered: April 2010
Junior Member

My use case is: I want to render an image on the server side. I'm using the AWT-APIs for this.

My problem: I'm getting a deadlock when calling the method "Toolkit.getDefaultToolkit()" in an OSGi environment (equinox or felix).

Here is a test case to reproduce the problem:

Run the .cmd-file "run-with-equinox.cmd". If you get the message "After 10 seconds, the AWT Toolkit still could not be initialized. This is a bug!" you have reproduced the error.

The error only occurs an a windows system. On an ubuntu system (probably on every unix based system) the test case produces no error.

I noticed some strange behavior while trying to solve the problem:
- pressing "enter" in the console from which I control the OSGi runtime resolves the lock
- jvisualvm cannot create a thread dump while the deadlock exists

Has anyone an idea? Where is the error?


p.s.: To understand the error I stepped through the sourcecode and got finally into the class "sun.awt.window.WToolkit". For a better understanding of the problem have a look at the sourcecode of "" (see end of the post for a shortened version)
In the constructor of this class a new deamon thread is started. After starting this thread "wait()" is called. The deamon thread should notify the main thread after finishing. This deamon thread calls the native method "init()" from the library "awt.dll" to do some initializing stuff. This call does not return and so the thread never calls the method notifyAll() to notify the main thread.


public class WToolkit extends SunToolkit implements Runnable {


 public WToolkit() {
        // Startup toolkit threads
        if (PerformanceLogger.loggingEnabled()) {
            PerformanceLogger.setTime("WToolkit construction");

        sun.java2d.Disposer.addRecord(anchor, new ToolkitDisposer());

        synchronized (this) {
            // Fix for bug #4046430 -- Race condition
            // where notifyAll can be called before
            // the "AWT-Windows" thread's parent thread is 
            // waiting, resulting in a deadlock on startup.

             * Fix for 4701990.
             * AWTAutoShutdown state must be changed before the toolkit thread
             * starts to avoid race condition.

            if (!startToolkitThread(this)) {
                Thread toolkitThread = new Thread(this, "AWT-Windows");

            try {
            catch (InterruptedException x) {

        // Enabled "live resizing" by default.  It remains controlled
        // by the native system though.

    public void run() {
        boolean startPump = init();


        synchronized(this) {

        if (startPump) {
            eventLoop(); // will Dispose Toolkit when shutdown hook executes
Re: Deadlock while calling "Toolkit.getDefaultToolkit()" in an OSGi environment [message #526617 is a reply to message #526602] Mon, 12 April 2010 12:49 Go to previous messageGo to next message
Ralf Ebert is currently offline Ralf Ebert
Messages: 168
Registered: July 2009
Senior Member
Hi Simon,

have you tried running the OSGi container with "-Djava.awt.headless=true" (see l#headless)? This should allow
to render images without running an event loop.

- Ralf

Read my Blog here:
Follow me on Twitter here:
Re: Deadlock while calling "Toolkit.getDefaultToolkit()" in an OSGi environment [message #529827 is a reply to message #526602] Tue, 27 April 2010 11:45 Go to previous message
Simon Eiersbrock is currently offline Simon Eiersbrock
Messages: 2
Registered: April 2010
Junior Member
Hi Ralf,

thanks for the answer. I tried it, but this does not help.

I found the solution for my problem in the Apache Felix mailing list. It is a windows bug, which has effects to the JVM:

- Simon
Previous Topic:Software update runs into "StorageException"
Next Topic:OSGI console secured telenet port
Goto Forum:

Current Time: Tue Oct 21 21:36:11 GMT 2014

Powered by FUDForum. Page generated in 0.01621 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software