In Java, I have 2 threads that are both accessing (not modifying) the same BufferedImage. I’m simply drawing the buffered image into a separate Graphics2D objects with code like this.
Graphics2D g = getGraphics();
g.drawImage(myImage, 0, 0, null);
Is there any reason I need to synchronize access to the images?
I know about the AWTEventThread not being thread safe etc. I’m just building some BufferedImages in a background thread.
Thanks much…
(The title of your question doesn’t actually match the scenario described in the body, so I’m assuming that you are asking about both cases …)
The two threads that are just accessing an (at that point) non-changing
BufferedImagewould not need to synchronize between themselves.However, there does need to be a happens-before relationship between the thread that created and initialized the
BufferedImageobject in the first place and any threads that subsequently read it. Without that synchronization point, the reading threads might see stale values for parts of the image data structure.