Can't bring Java window to front when busy
I have written an image processing application with the GUI part written in Java and the number crunching part is written in C and is called via JNI.
My problem is that it takes 20 - 30 seconds for the application to process an image, and during this time the application disappears from the Task Switcher (the Alt-Tab thingy) and it is not possible to move the application's window to the front (th开发者_StackOverflow中文版is is my main concern). It is still possible to bring the application to front via the task bar.
Some more info:
- The application isn't stuck or anything, I can see that it updates a progress bar as expected.
- When the calculation is done, the application will show up the Task Switcher and can become the top window again. If I start a new calculation the application will disappear from the Task Switcher again.
- The JNI call is made on a separate thread (from EDT), I have tried both the main thread and a created thread.
- The EDT is not blocked. I have added printfs in WindowListener's and WindowFocusListener's methods and if the window lose focus the appropriate methods are called.
- On Mac OS X the application works without problem.
- This is on Java 1.6 on Windows 2003 Server.
- First I thought that it was openMP that was doing something nasty with the threads, but turning it off didn't make any difference.
- The JNI lib is compiled with MinGW 4.5.
It seems to me that Windows expects that an application answer/send some requests or else it will be thrown out of the Task Switcher. But I don't even know enough about Windows programming to even be able to google for an answer. Can someone give me some pointers?
I hate to say this as an answer, but are you sure that the number crunching is happening on a separate thread from the EDT? Because seriously, it shouldn't be behaving this way at all. There's a logical reason for it, I'm sure, and the most obvious is, you're blocking the EDT while you number crunch.
Maybe you think you're creating a new thread, but you're not?
Runnable r = new Runnable() { public void run() { ClassName.this.executeJNI(); } }; new Thread(r).start();
Either that, or something in the number crunching is locking a resource that the EDT thread needs - but I don't even know what this could possibly look like.
精彩评论