1 package org.codehaus.mojo.exec;
2
3
4
5
6
7
8
9
10 public class MainUncooperative extends Thread
11 {
12 public static final String SUCCESS = "1(interrupted)(f)2(f)";
13
14 public static void main( String[] args )
15 throws InterruptedException
16 {
17 Thread daemonThread = new MainUncooperative();
18 daemonThread.setDaemon( true );
19 daemonThread.start();
20 Thread.sleep( 1000 );
21
22 }
23
24 final long SIMWORKTIME = 15*1000;
25
26 public void run()
27 {
28 boolean interruptedOnce = false;
29 long startedTime = System.currentTimeMillis();
30 for(int lap = 1; true; lap++ )
31 {
32 long remainingWork = SIMWORKTIME - (System.currentTimeMillis() - startedTime);
33 if ( remainingWork <= 0 )
34 {
35 break;
36 }
37 try
38 {
39 System.out.print( lap );
40 Thread.sleep(remainingWork);
41 System.out.print( "(done)" );
42 break;
43 }
44 catch ( InterruptedException e )
45 {
46
47
48 if ( ! interruptedOnce )
49 {
50 System.out.print( "(interrupted)" );
51 }
52 interruptedOnce = true;
53
54
55 }
56 finally
57 {
58 System.out.print("(f)");
59 }
60 }
61 }
62 }