Board index » jbuilder » SwingUtilities invokeLater

SwingUtilities invokeLater


2003-10-09 08:19:46 AM
jbuilder11
I remember that while working on Windows, when I wanted to run a separate
thread to aupdate a swing component (for example a memory indicator), I
had run the thread with SwingUtilities.invokeLater(). However, while
working under Linux, I forgot to use it. The component worked fine. Is
the implementation of threads and thread synchronization in Java different
on Windows and Linux. If so, where can I find more information about what
should I pay attention when developing multiplatform Java Application?
 
 

Re:SwingUtilities invokeLater

The best advice I can give on developing multi-threaded apps is to assume
nothing about the behaviour, scheduling or timeliness of threads. You
should always do Swing updated in the Swing update thread [using, as you
mentioned, invokeLater() or invokeAndWait()]. It may be that you won't
*need* to in one particular instance or platform, but you still *should*.
On Thu, 09 Oct 2003 02:19:46 +0200, you wrote in
borland.public.jbuilder.java.swing:
Quote
I remember that while working on Windows, when I wanted to run a separate
thread to aupdate a swing component (for example a memory indicator), I
had run the thread with SwingUtilities.invokeLater(). However, while
working under Linux, I forgot to use it. The component worked fine. Is
the implementation of threads and thread synchronization in Java
different
on Windows and Linux. If so, where can I find more information about what
should I pay attention when developing multiplatform Java Application?

--
Stew Murrie
XXXX@XXXXX.COM
Use Opera!
 

Re:SwingUtilities invokeLater

It is very different (depending on which JDK version, which Linux
version), but you should definitely NOT change your code to leave it up
to the OS in this situation. You just may have not hit the contention in
Linux yet, and in any event can't depend on that behavior being
consistent from release to release. Using SwingUtilities insures that
you won't have a problem by making the single AWT thread responsible for
updating all the UI, regardless from which thread the original UI
request came from.
In terms of resources, there is an interesting section in the "Taming
Java Threads" book by Holub (or go to
www.holub.com/publications/articles/index.html for lots of
interesting stuff by this guy) on differences in threading between
Windows and *nix (primarily Solaris, but the issues apply).
Tad Frysinger
[TeamB]
Aleksandar Pecanov wrote:
Quote
I remember that while working on Windows, when I wanted to run a separate
thread to aupdate a swing component (for example a memory indicator), I
had run the thread with SwingUtilities.invokeLater(). However, while
working under Linux, I forgot to use it. The component worked fine. Is
the implementation of threads and thread synchronization in Java different
on Windows and Linux. If so, where can I find more information about what
should I pay attention when developing multiplatform Java Application?

 

{smallsort}

Re:SwingUtilities invokeLater

Sorry for crashing this thread....but I just wondered, since the thread is
about invokeLater if someone could advise me on if this could be part of my
problem too...
I have an application that uses
gridBagLayout as the layout manager.
Somewhere in the code the app sets up for an image (A4...like letter size)
to be displayed AND in a separate thread (implementing Runnable) calls a
method that will set the scroll bar to the bottom of the image. It sets up
the run method, and then calls SwingUtils.invokeLater.
The problem is this is unstable. Often, but not always, the image stays
(with scrollbar) at the top. I may have misunderstood but I tried a few
things, one being calling it as "synchronized" which at first I thought
helped but the problem returned. Also I tried changing the invokeLater to
"invokeAndWait" and still it happens.
This is inherited code, I didn't write it, and I surely have to spend more
time checking all the logic in it...but generally it seems like nothing I do
can insure that the scrollToBottom (one of the methods) works and is done
corectly before continuing.
I am not writing out the code here, so I am not necessarily asking for
someone to solve this for me, but if anyone had some similar experience and
could share general tips about this I would be interested to hear.
Thanks,
Jim
"In theory there is no difference between theory and practice,
but not in practice."
====================================================
"Tad Frysinger" < XXXX@XXXXX.COM >skrev i melding
Quote
It is very different (depending on which JDK version, which Linux
version), but you should definitely NOT change your code to leave it up
to the OS in this situation. You just may have not hit the contention in
Linux yet, and in any event can't depend on that behavior being
consistent from release to release. Using SwingUtilities insures that
you won't have a problem by making the single AWT thread responsible for
updating all the UI, regardless from which thread the original UI
request came from.

In terms of resources, there is an interesting section in the "Taming
Java Threads" book by Holub (or go to
www.holub.com/publications/articles/index.html for lots of
interesting stuff by this guy) on differences in threading between
Windows and *nix (primarily Solaris, but the issues apply).

Tad Frysinger
[TeamB]

Aleksandar Pecanov wrote:
>I remember that while working on Windows, when I wanted to run a
separate
>thread to aupdate a swing component (for example a memory indicator), I
>had run the thread with SwingUtilities.invokeLater(). However, while
>working under Linux, I forgot to use it. The component worked fine. Is
>the implementation of threads and thread synchronization in Java
different
>on Windows and Linux. If so, where can I find more information about
what
>should I pay attention when developing multiplatform Java Application?
>