import java.awt.AWTException;
import java.awt.Robot;

public class AllocatetaskThread  extends Thread 
{

	
	private SeverList serverlist_list = null;
	private TaskList tasklist_list = null;

	Robot  r   =   null;
	 
	public AllocatetaskThread(SeverList serverlist)
	{
		this.serverlist_list=serverlist;
	}
	
	public   void run() 
	{
		
		try {
			 r= new   Robot();
			 System.out.println(serverlist_list.get_host_name()+":内部分配任务线程启动，内存："+serverlist_list.get_all_Memory());
			//循环处理，直到为空
			while( true )
			{
				if(serverlist_list.queue.isEmpty())
				{
					serverlist_list.isDispose = true;
				}
				else {
					tasklist_list =  serverlist_list.queue.poll();
					serverlist_list.isDispose = false;
					while (  serverlist_list.rest_Memory < tasklist_list.get_need_Memory())
						{   
						//r.delay(10);
					    }
					serverlist_list.syntask.reduce_memory(serverlist_list, tasklist_list);
					
					serverlist_list.isDispose = true;		
					Thread.sleep(tasklist_list.get_time());
				
					serverlist_list.syntask.add_memory(serverlist_list, tasklist_list);
							
					System.out.println("极端节点-执行完成："+tasklist_list.get_taskName());
				}		
			}		
			
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (AWTException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	


}


































