@ Override public void log ( StopWatch sw ) { if ( ! m_queue . offer ( sw . freeze ( ) ) ) m_rejectedStopWatches . getAndIncrement ( ) ; if ( m_collectorThread == null ) { synchronized ( this ) { // // Ensure that there is no race condition starting the thread. // Note that under the JVM5 memory model this also requires // that the field is declared as "volatile", or else the compiler // may do something nasty. // if ( m_collectorThread == null ) { m_collectorThread = new CollectorThread ( ) ; m_collectorThread . setName ( "Speed4J PeriodicalLog Collector Thread" ) ; m_collectorThread . setDaemon ( true ) ; m_collectorThread . start ( ) ; } } } }
This method also starts the collector thread lazily .