Hi I have a paint method that is drawing an image and I have another method that is constantly modifying the image to be drawn however I experience concurrency exceptions now and again. What is the most efficient way to resolve this please? I know I could use synchronized blocks on the buffered image but then it throws up warnings on synchronizing a none final variable.
private BufferedImage img;
public void modImage(BufferedImage image) {
img = image;
}
public void paintComponent(Graphics g) {
if (img != null) {
g.drawImage(img, 0, 0, this);
}
}
synchronized (img), which is what "use synchronized blocks on the buffered image" sounds like.synchronizedand non-final variables, but IMO the signal-to-noise ratio of that warning is way too low. (Why not a "calling method on non-final variable" warning?)