Skip to main content


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 EiersbrockFriend
Messages: 3
Registered: April 2010
Junior Member
Hi,

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:
http://support.isr.de/download/isr/awt-osgi-problem.zip

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?

Thanks!


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 "WToolkit.java" (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.
             */
            AWTAutoShutdown.notifyToolkitThreadBusy();

            if (!startToolkitThread(this)) {
                Thread toolkitThread = new Thread(this, "AWT-Windows");
                toolkitThread.setDaemon(true);
                toolkitThread.start();
            }

            try {
                wait();
            }
            catch (InterruptedException x) {
            }
        }
        SunToolkit.setDataTransfererClassName(DATA_TRANSFERER_CLASS_NAME);

        // Enabled "live resizing" by default.  It remains controlled
        // by the native system though.
        setDynamicLayout(true);
    }

    public void run() {
        Thread.currentThread().setPriority(Thread.NORM_PRIORITY+1);
        boolean startPump = init();

       [..]

        synchronized(this) {
            notifyAll();
        }

        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 EbertFriend
Messages: 168
Registered: July 2009
Senior Member
Hi Simon,

have you tried running the OSGi container with "-Djava.awt.headless=true" (see
http://java.sun.com/j2se/1.4.2/docs/guide/awt/AWTChanges.htm l#headless)? This should allow
to render images without running an event loop.

- Ralf



--
Read my Blog here: http://www.ralfebert.de/blog/
Follow me on Twitter here: http://twitter.com/ralfebert/
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 EiersbrockFriend
Messages: 3
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:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4809647

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


Current Time: Thu Mar 28 21:03:19 GMT 2024

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

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

Back to the top