Java setRGB在可运行的Mandelbrot集合中不工作

Java setRGB在可运行的Mandelbrot集合中不工作,java,parallel-processing,runnable,mandelbrot,Java,Parallel Processing,Runnable,Mandelbrot,我需要使用并行编程绘制Mandelbrot集,使用的语言是Java。我使用可运行的任务来实现这一点。由于setRGB是同步的,所以我不需要锁来控制并发性,而且所有线程之间共享的BuffereImage也是并行访问的,因此它不应该是并发性问题。代码如下: public class MandelParalelo extends JFrame implements Runnable{ private final int MAX_ITER = 100000; private final doubl

我需要使用并行编程绘制Mandelbrot集,使用的语言是Java。我使用可运行的任务来实现这一点。由于setRGB是同步的,所以我不需要锁来控制并发性,而且所有线程之间共享的BuffereImage也是并行访问的,因此它不应该是并发性问题。代码如下:

public class MandelParalelo extends JFrame 
implements Runnable{
 private final int MAX_ITER = 100000;
 private final double ZOOM = 150;
 private static BufferedImage Imagen;
 private double zx, zy, cX, cY, tmp;
 private int nTareas = 6;
 private int linf, lsup;

 public void run()
 {
    for (int y = linf; y < lsup; y++) {
       for (int x = 0; x < getWidth(); x++) {
         zx = zy = 0;
         cX = (x - 400) / ZOOM;
         cY = (y - 300) / ZOOM;
         int iter = MAX_ITER;
         while (zx * zx + zy * zy < 4 && iter > 0) {
                 tmp = zx * zx - zy * zy + cX;
                 zy = 2.0 * zx * zy + cY;
                 zx = tmp;
                 iter--;
         }
         Imagen.setRGB(x, y, iter | (iter << 8));//setRGB es synchronized
   }
  }
 }
public MandelParalelo(int i, int s)
{
  linf = i;
  lsup = s;
}

public MandelParalelo() {
  super("Conjunto de Mandelbrot");
  setBounds(100, 100, 800, 600);
  setResizable(false);
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  Imagen = new BufferedImage(getWidth(), getHeight(),
      BufferedImage.TYPE_INT_RGB);
  ExecutorService ejecutor = Executors.newFixedThreadPool(8);
  int inf = 0, tVentana = getHeight()/nTareas, sup = tVentana;
    
    for(int i = 0; i < nTareas; i++)
    {  
        ejecutor.execute(new MandelParalelo(inf, sup));
        inf = sup;
        sup += tVentana; 
    }
    
    ejecutor.shutdown();
    
    while(!ejecutor.isTerminated()){}
  

}
public void paint(Graphics g) {
  g.drawImage(Imagen, 0, 0, this);
 }
public static void main(String[] args) {
  new MandelParalelo().setVisible(true);     
 }
}
公共类Mandelello扩展了JFrame
实现可运行{
私人最终整数最大值=100000;
私人最终双变焦=150;
专用静态缓冲区映像;
私人双zx、zy、cX、cY、tmp;
私人住宅面积=6;
私人int linf,lsup;
公开募捐
{
对于(int y=linf;y0){
tmp=zx*zx-zy*zy+cX;
zy=2.0*zx*zy+cY;
zx=tmp;
国际热核聚变实验堆;
}

图像setRGB(x,y,iter |(举个例子,先读一读,让它使用单线程。@camickr是的,在单线程工作中用ejector替换你的while循环。虽然,我认为等待终止破坏了你对并行的尝试…我想我不理解并行编程的概念。我把线程池从8改为1,但它仍然不起作用。我知道我只使用ExecutorService来使用多个处理器处理谨慎的任务。例如,演示了如何加载缩略图。我不知道您可以将mandelbrot分解为八个部分,然后将其重新组合成一个。