/*
 * Created on 25.05.2005
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */

/**
 * @author Home
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class Printer extends Thread{
	
	private String[] printQu;		
	private int in=0;
	private int out=0;
	
	public Printer(){printQu = new String[100];};
	
	// synchronisieren
	private synchronized void enqueue(String val)
	{
		printQu[in]=val;
				
		// Anderen Client-Thread rechnen lassen, synchronized entfernen und 
		// Verlorengegangenen Druckauftrag damit erzeugen
	  	// yield();
		
		in=in+1;
	}
		
	private synchronized void dequeue_and_print()
	{
		if(printQu[out]!=null)
			System.out.println(printQu[out] + " gedruckt");		
		out=out+1;
	}
	
	public void announcePrintJob(String fileName)
	{
		enqueue(fileName);
	}
	
		
	public void run()
	{
		while (true)
		{
			if(in>out)
				dequeue_and_print();			
		}	
	}
}
