Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

JNI C++ importatn process

Thread view: 
Marcelo - 30 Sep 2005 16:22 GMT
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
thanks a lot,

Marcelo


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.