This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

is repaint() still thread safe?  RSS feed

 
Tom Farrell
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Repaint not thread safe anymore.

I was always under the impression that JComponent.repaint() was always executed on the edt. Is this not the case anymore?
 
Rob Camick
Ranch Hand
Posts: 2787
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was always under the impression that JComponent.repaint() was always executed on the edt.


You can always look at the source code to see what is going on.

All the repaint() method does (in JDK6_7) is invoke the RepaintManager.addDirtyRegion(...) method. This adds the components bounds to a Hashmap. Some of the code in this method is synchronized, some is not (there is a comment explaining why part of the code is not synchronized). Then at the end it ultimately invokes SwingUtilities.invokeLater(). So it appears to be thread safe.

I have no idea if the code was changed in newer versions.

From my point of view, the only time I invoke repaint() is when I've changed a property on a component so I'm already executing on the EDT so I don't worry about it. I'm not sure why I would invoke repaint outside of the EDT.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!