Re: About swing Timer and synchronized



marpauser@xxxxxxxxx wrote:
Hello,
I would like your comment about synchronized and
SwingUtilities.invokeLater in this example with javax.swing.Timer:
[snipped code]

First, use EventQueue.invokeLater instead.

javax.swing.Timer calls the actionPerformed on the EDT. Its generally a bad idea to use synchronize on the EDT, because you might block it for an arbitrarily long time, and make the GUI unresponsive.

To learn more, about thread safety, I suggest reading the book Java Concurrency In Practice.

<http://virtualinfinity.net/wordpress/technical-book-recommendations/java-concurrency-in-practice/>

As well as the sun Swing tutorials related to threading.

There are plenty of ways to pass information to and from the event dispatch thread (or any other single thread) that are preferable over using synchronize.

Hope this helps,
Daniel.


--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
.



Relevant Pages

  • Re: About swing Timer and synchronized
    ... As well as the sun Swing tutorials related to threading. ... using synchronize. ... but after a long time it doesn't fires its event: I never stop Timer ... Seems that also without synchronized problem stays. ...
    (comp.lang.java.programmer)
  • Re: How can I select outlook contact fields to be synchronized to Axim
    ... > the controls to tell it which, if not all phone numbers should be ... There's plenty of screen room on the X3 ... will synchronize the entire contact item, ...
    (microsoft.public.outlook.general)