Hi,
I have a problem with my JNI application. Actually the C++ application
that is called from my java program is very very important. Because the
calculations last a lot of the time, I would like to know how to manage
them like as background thread.
I am using a link between GUI and C++, but with this calculation
problem, the GUI gets blocked.
what can I do?
Marcelo
Andrew Thompson - 30 Sep 2005 16:56 GMT
> I am using a link between GUI and C++, but with this calculation
> problem, the GUI gets blocked.
>
> what can I do?
Hand the call to the JNI code off to a Thread..
<http://www.physci.org/guifaq.jsp#2.1>
..then give the end user a 'progress dialog' (or something)
<http://www.physci.org/guifaq.jsp#2.2>
Marcelo - 30 Sep 2005 17:39 GMT
because it is inside a GUI
should I use a SwingUtilities ?
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
greatC++();
}
});
thanks
Marcelo
Thomas Fritsch - 30 Sep 2005 18:35 GMT
> because it is inside a GUI
> should I use a SwingUtilities ?
[quoted text clipped - 4 lines]
> }
> });
NOOOO! With SwingUtilities.invokeLater you tell Java to call greatC++()
from the GUI(!) thread. Hence the GUI will be blocked as long as it runs
greatC++().
Instead you want greatC++() to be called by ANOTHER thread. Create a new
Thread and then start it by yourself.
I recommend reading a good text-book (or the Java tutorial) about the
Thread and Runnable stuff.

Signature
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
Roedy Green - 30 Sep 2005 21:18 GMT
>javax.swing.SwingUtilities.invokeLater(new Runnable() {
> public void run() {
> greatC++();
> }
>});
Definitely not. Everything will come to grinding halt when that great
c task hogs the Swing event thread. You need a NEW background thread
to run your big task on.
See http://mindprod.com/jgloss/thread.html
In particular look at the SwingWorker class.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Marcelo - 03 Oct 2005 12:59 GMT