Clover Coverage Report - Exec Maven Plugin 1.1
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
20   78   9   4
6   56   0.45   5
5     1.8  
1    
 
  MainWithThreads       Line # 9 20 0% 9 31 0% 0.0
 
No Tests
 
1    package org.codehaus.mojo.exec;
2   
3    import java.util.Timer;
4    import java.util.TimerTask;
5   
6    /**
7    * @author <a href="mailto:dsmiley@mitre.org">David Smiley</a>
8    */
 
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    * both daemon threads will be interrupted as soon as the non daemon thread is done.
16    * the responsive daemon thread will be interrupted right away.
17    * - if the timer is cancelled (using 'cancelTimer' as argument), the timer will die on itself
18    * after all the other threads
19    * - if not, one must use a time out to stop joining on that unresponsive daemon thread
20    **/
 
21  0 toggle public static void main( String[] args )
22    {
23    // long run so that we interrupt it before it ends itself
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    // Timer in Java <= 6 aren't interruptible
31  0 final Timer t = new Timer( true );
32   
33  0 if ( optionsContains( args, "cancelTimer" ) )
34    {
35  0 t.schedule( new TimerTask()
36    {
 
37  0 toggle public void run()
38    {
39  0 System.out.print( "(cancelled timer)" );
40  0 t.cancel();
41    }
42    }, 400 );
43    }
44    }
45   
 
46  0 toggle 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   
 
59  0 toggle public MainWithThreads( int millisecsToSleep, String message )
60    {
61  0 this.millisecsToSleep = millisecsToSleep;
62  0 this.message = message;
63    }
64   
 
65  0 toggle public void run()
66    {
67  0 try
68    {
69  0 Thread.sleep( millisecsToSleep );
70    }
71    catch ( InterruptedException e ) // IE's are a way to cancel a thread
72    {
73  0 System.out.print( "(interrupted " + message + ")" );
74  0 return;
75    }
76  0 System.out.print( message );
77    }
78    }