package org.helioviewer.jhv.display;

import java.util.ArrayList;

public class Displayer{
	
    private static Displayer instance = new Displayer();
    private final ArrayList<DisplayListener> listeners = new ArrayList<DisplayListener>();
    private final ArrayList<RenderListener> renderListeners = new ArrayList<RenderListener>();
    private GL3DComponentFakeInterface gl3dcomponent;
	private Object lock = new Object();
	private int queue = 0;

    public void register(GL3DComponentFakeInterface gl3dcomponent){
    	this.gl3dcomponent = gl3dcomponent;
    }
	public static Displayer getSingletonInstance() {
        if (instance == null) {
            throw new NullPointerException("Displayer not initialized");
        }
        return instance;
    }
    public void addListener(final DisplayListener listener) {
        listeners.add(listener);
    }
    
    public void removeListener(final DisplayListener renderListener) {
    	synchronized(renderListener){
    		listeners.remove(renderListener);
    	}
    }
    public void addRenderListener(final RenderListener renderListener) {
    	synchronized(renderListener){
    		renderListeners.add(renderListener);
    	}
    }
    public void removeRenderListener(final RenderListener listener) {
    	synchronized(renderListeners){
    		renderListeners.remove(listener);
    	}
    }    
    public void render(){
    	synchronized(renderListeners){
	        for(final RenderListener renderListener : renderListeners) {
	        	renderListener.render();
	        }
    	}
    }

    public void display(){
    	int queuecopy;
    	synchronized(lock ){
    		queue ++;
    		queuecopy=queue;
    	}
    	if(queuecopy==1){
    		while(queue>0){

    	    	synchronized(listeners){
			        for(final DisplayListener listener : listeners) {
			            listener.display();
			        }
    	    	}
		    	queue--;
	    	}
    	}
    }
    public void animate(){
    	gl3dcomponent.activate();
    }
    public void stopAnimate(){

    	gl3dcomponent.deactivate();
    }
}

@@ -58,16 +58,100 @@
 rayList;
+%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Executors;
 %0A%0Apublic
@@ -170,20 +170,17 @@
 ayer%7B%0A%09%0A
-    
+%09
 private 
@@ -464,25 +464,28 @@
 ponent;%0A
-%09
+    
 private 
 Object l
@@ -480,58 +480,73 @@
 ate 
-Object lock = new Object();%0A%09private int queue = 0
+ExecutorService displayPool = Executors.newSingleThreadExecutor()
 ;%0A%0A 
@@ -1638,33 +1638,34 @@
 %7D%0A    %7D%0A
-%0A
     p
-ublic
+rivate
  void 
+t
 display(
@@ -1671,151 +1671,8 @@
 ()%7B%0A
-    %09int queuecopy;%0A    %09synchronized(lock )%7B%0A    %09%09queue ++;%0A    %09%09queuecopy=queue;%0A    %09%7D%0A    %09if(queuecopy==1)%7B%0A    %09%09while(queue%3E0)%7B%0A%0A    %09
     
@@ -1697,18 +1697,16 @@
 eners)%7B%0A
-%09%09
 %09       
@@ -1756,18 +1756,16 @@
 ners) %7B%0A
-%09%09
 %09       
@@ -1789,18 +1789,16 @@
 play();%0A
-%09%09
 %09       
@@ -1809,52 +1809,213 @@
    %09
+%7D%0A
     
-%09
 %7D%0A
-%09%09    %09queue--;%0A%09
+    private final class DisplayTask implements Runnable%7B%0A%09%09@Override%0A%09%09public void run() %7B%0A%09%09%09tdisplay();%0A%09%09%7D%0A
     
-%09
 %7D%0A    
-%09%7D
+public void display()%7B%0A    %09displayPool.submit(new DisplayTask());
 %0A    %7D%0A
+   %0A
     

Fix the sequential displaying