Re: About swing Timer and synchronized
- From: Daniel Pitts <newsgroup.spamfilter@xxxxxxxxxxxxxxxxxxx>
- Date: Thu, 15 Nov 2007 14:23:17 -0800
marpauser@xxxxxxxxx wrote:
Hello,[snipped code]
I would like your comment about synchronized and
SwingUtilities.invokeLater in this example with javax.swing.Timer:
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/>
.
- Follow-Ups:
- Re: About swing Timer and synchronized
- From: marpauser
- Re: About swing Timer and synchronized
- References:
- About swing Timer and synchronized
- From: marpauser
- About swing Timer and synchronized
- Prev by Date: Re: Comparing enum to a String failing...
- Next by Date: Re: Great SWT Program
- Previous by thread: About swing Timer and synchronized
- Next by thread: Re: About swing Timer and synchronized
- Index(es):
Relevant Pages
|