1 16 17 package org.apache.jetspeed.daemon.impl.util; 18 19 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 20 import org.apache.jetspeed.services.logging.JetspeedLogger; 21 22 29 public class ThreadGroupJoin 30 { 31 34 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(ThreadGroupJoin.class.getName()); 35 36 39 public static void join( ThreadGroup tg ) 40 { 41 join( tg, null, 0 ); 43 } 44 45 48 public static void join( ThreadGroup tg, 49 String source ) 50 { 51 join( tg, source, 100 ); 52 } 53 54 58 public static void join( ThreadGroup tg, 59 String source, 60 int interval ) 61 { 62 63 Thread [] threads = new Thread [ tg.activeCount() ]; 64 65 tg.enumerate( threads ); 66 67 69 long begin = System.currentTimeMillis(); 70 71 for ( int i = 0; i < threads.length; ++i ) { 72 73 if ( !threads[i].interrupted() ) 74 { 75 try 76 { 77 if ( threads[i] != null ) 78 { 79 threads[i].join(); 80 81 if ( i != 0 && 84 i % interval == 0 && 85 source != null ) 86 { 87 long seconds = ( System.currentTimeMillis() - begin ) / 1000; 88 begin = System.currentTimeMillis(); 89 90 if ( logger.isInfoEnabled() ) 91 { 92 logger.info( source + ": has completed " + i + " threads in " + seconds + " second(s)" ); 93 } 94 95 } 96 97 } 98 99 } 100 catch (InterruptedException e) 101 { 102 logger.info( "Thread: " + threads[i].getName() + " -> DONE"); 103 } 105 } 106 107 } 108 109 110 } 111 112 } 113 114 115 | Popular Tags |