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

I am using some 3rd party AWT components in a desktop application. The component's layout has been changed in the method paint()

and this causes very strange behavior. This seems to have been fixed by adding a keyword synchronized

to the paint () method, but is it safe to do so?

+2


a source to share


2 answers


It looks like the method paint()

is being called outside of the event dispatch thread , which can indeed cause very strange behavior, so this should never be done.



Instead, paint()

the application code should only callrepaint()

+3


a source


The paint method should only be called on one thread, the Dispatch Event thread, so there is no need to synchronize. I would guess that the root of the problem lies in how the components are used. Check out this link for some ideas around concurrency in the user interface.



+1


a source







All Articles