1 |
|
package org.codehaus.mojo.exec; |
2 |
|
|
3 |
|
import java.util.Timer; |
4 |
|
import java.util.TimerTask; |
5 |
|
|
6 |
|
|
7 |
|
@author |
8 |
|
|
|
|
| 0% |
Uncovered Elements: 31 (31) |
Complexity: 9 |
Complexity Density: 0.45 |
|
9 |
|
public class MainWithThreads extends Thread |
10 |
|
{ |
11 |
|
public static final String ALL_EXITED = "t1(interrupted td)(cancelled timer)"; |
12 |
|
public static final String TIMER_IGNORED = "t1(interrupted td)"; |
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
21 |
0
|
public static void main( String[] args )... |
22 |
|
{ |
23 |
|
|
24 |
0
|
Thread responsiveDaemonThread = new MainWithThreads( 60000, "td" ); |
25 |
0
|
responsiveDaemonThread.setDaemon( true ); |
26 |
0
|
responsiveDaemonThread.start(); |
27 |
|
|
28 |
0
|
new MainWithThreads( 200, "t1" ).start(); |
29 |
|
|
30 |
|
|
31 |
0
|
final Timer t = new Timer( true ); |
32 |
|
|
33 |
0
|
if ( optionsContains( args, "cancelTimer" ) ) |
34 |
|
{ |
35 |
0
|
t.schedule( new TimerTask() |
36 |
|
{ |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
37 |
0
|
public void run()... |
38 |
|
{ |
39 |
0
|
System.out.print( "(cancelled timer)" ); |
40 |
0
|
t.cancel(); |
41 |
|
} |
42 |
|
}, 400 ); |
43 |
|
} |
44 |
|
} |
45 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
46 |
0
|
private static boolean optionsContains( String[] args, String option )... |
47 |
|
{ |
48 |
0
|
for (int i = 0; i < args.length; i++ ) |
49 |
|
{ |
50 |
0
|
if ( args[i].equals( option ) ) |
51 |
0
|
return true; |
52 |
|
} |
53 |
0
|
return false; |
54 |
|
} |
55 |
|
|
56 |
|
private int millisecsToSleep; |
57 |
|
private String message; |
58 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
59 |
0
|
public MainWithThreads( int millisecsToSleep, String message )... |
60 |
|
{ |
61 |
0
|
this.millisecsToSleep = millisecsToSleep; |
62 |
0
|
this.message = message; |
63 |
|
} |
64 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
65 |
0
|
public void run()... |
66 |
|
{ |
67 |
0
|
try |
68 |
|
{ |
69 |
0
|
Thread.sleep( millisecsToSleep ); |
70 |
|
} |
71 |
|
catch ( InterruptedException e ) |
72 |
|
{ |
73 |
0
|
System.out.print( "(interrupted " + message + ")" ); |
74 |
0
|
return; |
75 |
|
} |
76 |
0
|
System.out.print( message ); |
77 |
|
} |
78 |
|
} |