1 27 28 package javax.management.timer; 29 30 import java.util.*; 31 32 33 34 class WorkerThread extends Thread 35 { 36 37 Scheduler scheduler = null; 38 39 public int m_current_indent_count = 0; 41 public StringBuffer m_current_indent_buffer = null; 42 43 44 public WorkerThread(Scheduler s,String nam) 45 { 46 super(nam); 47 scheduler = s; 48 m_current_indent_buffer = new StringBuffer (); 49 } 50 51 52 synchronized void wakeUp() 53 { 54 notifyAll(); 55 } 56 57 58 synchronized void waitUntilAsked() 59 { 60 while ((scheduler.ready_tasks.size() == 0) && (!scheduler.STOP_ALL)) 61 { 62 try 63 { 64 wait(100); 65 } 66 catch (InterruptedException iex) {} 67 } 68 } 69 70 71 public void run() 72 { 73 while ( (!scheduler.STOP_ALL) && (!scheduler.STOP_THIS) ) 74 try 75 { 76 waitUntilAsked(); 77 Runnable task = scheduler.getNextTask(); 78 if (task != null) task.run(); 79 } 80 catch (Exception ex) 81 { 82 System.err.println("Exception running task: "+ ex); 83 } 85 scheduler.NUM_THREADS_STOPPED += 1; 86 scheduler.TOTAL_THREADS -= 1; 87 } 88 89 } | Popular Tags |