开发者

Is it safe to synchronize java.awt.Container.paint(Graphics g)?

I'm using some 3rd party AWT components in a desktop application. The component's layout is changed within the paint() method, and 开发者_开发技巧this causes some very strange behaviour. This appears to be fixed by adding the synchronized keyword to the paint() method, but is this a safe thing to do?


It looks like the paint() method is called outside the event dispatch thread, which can indeed cause very strange behaviour, which is why it should never be done.

Instead of paint(), application code should only ever call repaint()


The paint method should only be called within one thread, the Event Dispatch Thread, so there is no need to synchronize. I would imagine that the root of the problem lies in how the components are being used. Take a look at this link for some ideas around concurrency in the UI.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜