1 17 18 package org.apache.avalon.cornerstone.threads.tutorial; 19 20 import org.apache.avalon.framework.logger.LogEnabled; 21 import org.apache.avalon.framework.logger.Logger; 22 23 29 public class Counter extends Thread implements LogEnabled 30 { 31 34 private Logger m_logger; 35 36 private int m_count = 10; 37 38 public void enableLogging( Logger logger ) 39 { 40 m_logger = logger; 41 } 42 43 protected Logger getLogger() 44 { 45 return m_logger; 46 } 47 48 public void run() 49 { 50 while( m_count > 0 ) 51 { 52 getLogger().info( "count: " + m_count ); 53 m_count--; 54 try 55 { 56 sleep( 1000 ); 57 } 58 catch( Throwable e ) 59 { 60 getLogger().info( "I've been interrupted." ); 61 m_count = -1; 62 } 63 } 64 getLogger().info( "Time to die." ); 65 m_logger = null; 66 } 67 } 68 69 | Popular Tags |