How to solve the setColor() problem with multithreading?
My fractal program uses a custom number of threads to draw the complete image. If I use just 1 thread, the image looks clean, if I use more threads some pixels of the image gets other colors. The problem ist the painting code:
g2d.setColor(col);
g2d.drawLine(x, y, x, y);
as it is necessary to first set the color of the graphics object and then draw the line. I can solve this pixel color problem by synchronizing the Graphics2D object:
synchronized (g2d){
g2d.setColor(col);
g2d.drawLine(x, y, x, y);
}
but this slows the code down to times where just 1 thread is calculating the image. Unfortunately, I can't find a draw() method that has a color parameter.
I tried to divide the panel into multiple BufferedImages (1 for each thread) which solves the pixel problem but only the first BufferedImage get's drawn.

