|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
TaskProcessor.java | 0% | 0% | 0% | 0% |
|
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 | 0 |
public TaskProcessor() {
|
16 | 0 |
msgs = new Vector();
|
17 |
} |
|
18 |
|
|
19 | 0 |
public synchronized void addTask( Runnable run) { |
20 | 0 |
msgs.addElement( run); |
21 | 0 |
this.notifyAll();
|
22 |
} |
|
23 |
|
|
24 | 0 |
public void run() { |
25 | 0 |
for( ; ; ) {
|
26 | 0 |
Runnable run = null;
|
27 | 0 |
synchronized( this) { |
28 | 0 |
while( msgs.size() == 0) {
|
29 | 0 |
try {
|
30 | 0 |
this.wait();
|
31 |
} catch( InterruptedException e) {
|
|
32 |
// do nothing
|
|
33 |
} |
|
34 |
} |
|
35 | 0 |
run = (Runnable)msgs.elementAt( 0); |
36 | 0 |
msgs.removeElementAt( 0); |
37 |
} |
|
38 | 0 |
try {
|
39 | 0 |
run.run(); |
40 |
} catch( RuntimeException e) {
|
|
41 |
// do nothing
|
|
42 |
} |
|
43 |
} |
|
44 |
} |
|
45 |
} |
|
46 |
|
|