SwingUtilities.invokeLater(doFinished); not working on MAc

J

jdilip

Hi
SwingUtilities.invokeLater(doFinished); line of SwingWorker class
doesnot execute on mac pc. The same code is working perfectly on
Windows 2000 and XP. After adding many System.out.Println().. i found
that my execution halts at the SwingUtilities.invokeLater(doFinished);
line. The application really hangs there. I have top force quit the
application. Note here i do not have any Swing GUI in picture. I have
certain class methods to access db and forward the data to the calling
app. My app used C++ and JNI to call my java methods. Please someone
tell me whether ther eis soome problem of the SwingWorker clas on mac
or some other thing.
Thanks
Dilip Jain
 
T

Thomas Hawtin

SwingUtilities.invokeLater(doFinished); line of SwingWorker class
doesnot execute on mac pc. The same code is working perfectly on
Windows 2000 and XP. After adding many System.out.Println().. i found
that my execution halts at the SwingUtilities.invokeLater(doFinished);
line. The application really hangs there. I have top force quit the
application. Note here i do not have any Swing GUI in picture. I have
certain class methods to access db and forward the data to the calling
app. My app used C++ and JNI to call my java methods. Please someone
tell me whether ther eis soome problem of the SwingWorker clas on mac
or some other thing.

There are many versions of SwingWorker.

It sounds like a deadlock of some form. If you get a stack dump it may
show up. I don't know the Mac way of doing things. On Windows it would
be Ctrl-Break from the console. On Linux Ctrl-\ from the console, or use
jstack <process-id>.

Tom Hawtin
 
S

Steve W. Jackson

Thomas Hawtin said:
There are many versions of SwingWorker.

It sounds like a deadlock of some form. If you get a stack dump it may
show up. I don't know the Mac way of doing things. On Windows it would
be Ctrl-Break from the console. On Linux Ctrl-\ from the console, or use
jstack <process-id>.

Tom Hawtin

There is no "Mac way" in Java, only Apple's JVM that is fully compliant
with Sun's JLS.

While I haven't got a copy of SwingWorker handy to try out, I can say
for absolutely, positively certain that using the invokeLater method on
EventQueue (and the SwingUtilities version simply calls the one in
EventQueue) does work on my Mac in 1.4.2. I've put a slightly modified
version of our app on here that uses this method in numerous places, and
all work as expected.

= Steve =
 
J

jdilip

I am using the 3rd version of SwingWorker Class

* This is the 3rd version of SwingWorker (also known as
* SwingWorker 3), an abstract class that you subclass to
* perform GUI-related work in a dedicated thread. For
* instructions on and examples of using this class, see:
*
* http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html
*
* Note that the API changed slightly in the 3rd version:
* You must now invoke start() on the SwingWorker after
* creating it.
 
J

jdilip

Ok, can you tell me how using the other way round you got your code/app
running on MAC instead of using SwingWorker or
SwingUtilities.invokelater();
 
T

Thomas Hawtin

There is no "Mac way" in Java, only Apple's JVM that is fully compliant
with Sun's JLS.

I don't understand what you are getting at. As far as I am aware
Ctrl-Break, Ctrl-\ and jstack are not in any of the specs. They are
system/JRE-specific. JLS defines the Java language, which the JVM
doesn't need to deal with.

Tom Hawtin
 
S

Steve W. Jackson

Ok, can you tell me how using the other way round you got your code/app
running on MAC instead of using SwingWorker or
SwingUtilities.invokelater();

It's "Mac", not "MAC"...

In order to use SwingUtilities.invokeLater, you should understand the
event handling mechanisms in Swing. That is, there's basically a single
event dispatching thread on which some important behaviors take place,
like firing action events, updating (painting) components, etc.

If you've got code that's not on the EDT and you want to do something
that should be on it, you pass a Runnable to the above method. Your
code keeps on going, having passed the Runnable. The Runnable's run()
method will be invoked when its turn on the EDT's queue comes up.

What platform you do that on isn't relevant. It's how Java Swing works.
My code was written on a PC, and the app in question is distributed for
Windows and Linux, but I'm a Mac user by preference. So I simply
brought the code over to my Mac, made some minor changes needed to
disable some code that required JNI code I don't have on my Mac, and ran
it to see how it works. The parts that used invokeLater() worked fine.

= Steve =
 
S

Steve W. Jackson

Thomas Hawtin said:
I don't understand what you are getting at. As far as I am aware
Ctrl-Break, Ctrl-\ and jstack are not in any of the specs. They are
system/JRE-specific. JLS defines the Java language, which the JVM
doesn't need to deal with.

Tom Hawtin

You're right -- your mention of "Mac way" referred to how to break the
app, not to something language related.

FWIW, "jstack" isn't available in my 1.4.2 implementation, though it is
in 1.5 (both Mac and Windows). But Mac OS X has a BSD-based heart, so
I'm assuming that whatever is useful in Linux or other "Unix-alikes"
would work here.

= Steve =
 
H

hiwa

Basically you don't need to wrap the SwingWorker
finished() method with the invokeLater(). SwingWorker
is already automatically handling the EDT issue for it.
And the finished() method is a callback that you should
not call from your code. So your use of invokeLater()
is an unnecessary redundancy at best, and, might be
harmful at worst.
 
C

Chris Uppal

SwingUtilities.invokeLater(doFinished); line of SwingWorker class
doesnot execute on mac pc. [...]
Note here i do not have any Swing GUI in picture.

If your application doesn't use Swing, why are you calling invokeLater() at all
?

-- chris
 
R

Roedy Green

It's "Mac", not "MAC"...

A MAC is the unique serial number burned into your Ethernet chip that
makes it possible for Ethernet to hit the ground running without some
scheme to first assign everyone unique addresses.
 
J

jdilip

I have a class which extends SwingWorker Class. And this common class
is used in my Swing app as well as non-swing app. My non-Swing app is
saught of helper class for other app using thru JNI. Thats why i am
using this class
 
J

jdilip

Is there any other way where in i can call the execution of the
doFininshed method instead of using
SwingUtilities.invokeLater(doFinished); so that i can test it.
 
S

steve

Hi
SwingUtilities.invokeLater(doFinished); line of SwingWorker class
doesnot execute on mac pc. The same code is working perfectly on
Windows 2000 and XP. After adding many System.out.Println().. i found
that my execution halts at the SwingUtilities.invokeLater(doFinished);
line. The application really hangs there. I have top force quit the
application. Note here i do not have any Swing GUI in picture. I have
certain class methods to access db and forward the data to the calling
app. My app used C++ and JNI to call my java methods. Please someone
tell me whether ther eis soome problem of the SwingWorker clas on mac
or some other thing.
Thanks
Dilip Jain

I program extensively on the mac using java , and i can say my
invokedLater(), is working.

which , JVM are you using 1.4 or 1.5?
 
S

steve

Is there any other way where in i can call the execution of the
doFininshed method instead of using
SwingUtilities.invokeLater(doFinished); so that i can test it.

O.K lets stop messing about, send us the code that does not work & i will
run it on my mac.
 
J

John C. Bollinger

I have a class which extends SwingWorker Class. And this common class
is used in my Swing app as well as non-swing app. My non-Swing app is
saught of helper class for other app using thru JNI. Thats why i am
using this class

You have a design problem here. A class that is not restricted to use
in the context of a Swing-based GUI should *not* extend SwingWorker. It
clearly isn't one -- it's more general than that.

Moreover, I agree with Chris's implication that you shouldn't be using
SwingUtilities.invokeLater() an a non-Swing application. You should not
be attempting to execute code on the event dispatch thread that doesn't
relate to producing or handling AWT events. It's plain incorrect. And
given that it isn't in fact working on Mac (and you want it to do), I'd
say it's high time that you went back and did it right.

I suppose that what you want is an asynchronous job execution mechanism.
It is a bit tricky to write one yourself, but eminently doable.
Alternatively, you may be able to find a general-purpose utility already
available that suits your purpose.
 
J

jdilip

Right, i want an asynchronous job execution mechanism. As you mentioned
there may be general-purpose utility already available that suits my
purpose. Are you aware of any such utility that can be handy for me.
 
J

jdilip

Right, i want an asynchronous job execution mechanism. As you mentioned
there may be general-purpose utility already available that suits my
purpose. Are you aware of any such utility that can be handy for me.
 
J

John C. Bollinger

Right, i want an asynchronous job execution mechanism. As you mentioned
there may be general-purpose utility already available that suits my
purpose. Are you aware of any such utility that can be handy for me.

I didn't realize you had posted this in addition to e-mailing me. Don't
do that. If you want a private response, e-mail. If a public one, or
you don't care, post.

For those interested, I offered the possibilities of using a
java.util.Timer and of using a thread pool, possibly one with only a
single thread. The latter is the general Java solution to asynchronous
job execution. The former is a bit of a hack that nevertheless can
emulate SwingUtilities.invokeLater() quite closely.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top