1 package nmp.util;
2
3 import java.util.Vector;
4
5 /***
6 * Creates a thread to sequentially execute the task that the user assigns to
7 * this processor <BR>
8 * NOTE: The thread must be started.
9 */
10 public class TaskProcessor
11 extends Thread
12 {
13 private Vector msgs;
14
15 public TaskProcessor() {
16 msgs = new Vector();
17 }
18
19 public synchronized void addTask( Runnable run) {
20 msgs.addElement( run);
21 this.notifyAll();
22 }
23
24 public void run() {
25 for( ; ; ) {
26 Runnable run = null;
27 synchronized( this) {
28 while( msgs.size() == 0) {
29 try {
30 this.wait();
31 } catch( InterruptedException e) {
32 // do nothing
33 }
34 }
35 run = (Runnable)msgs.elementAt( 0);
36 msgs.removeElementAt( 0);
37 }
38 try {
39 run.run();
40 } catch( RuntimeException e) {
41 // do nothing
42 }
43 }
44 }
45 }
This page was automatically generated by Maven