public void run(){
  if (isTransient) {
    throw new RuntimeException("Service is transient");
  }
  lock.lock();
  try {
    final long begin=System.currentTimeMillis();
    final int i=(int)snapshotCount % 2;
    final File file=new File(dataDir,BASENAME + i + EXT);
    if (!dataDir.exists()) {
      if (!dataDir.mkdirs() && !dataDir.mkdirs()) {
        throw new RuntimeException("Could not create: " + dataDir);
      }
    }
    final long entryCount;
synchronized (commitTimeIndex) {
      entryCount=SnapshotHelper.write(commitTimeIndex,file);
    }
    snapshotCount++;
    final long elapsed=System.currentTimeMillis() - begin;
    log.warn("snapshot: snapshotCount=" + snapshotCount + ", entryCount="+ entryCount+ ", file="+ file+ ", elapsed="+ elapsed);
  }
 catch (  Throwable t) {
    log.error(t.getMessage(),t);
    return;
  }
 finally {
    lock.unlock();
  }
}

public void run ( ) { if ( isTransient ) { throw new RuntimeException ( "Service is transient" ) ; } lock . lock ( ) ; try { final long begin = System . currentTimeMillis ( ) ; final int i = ( int ) snapshotCount % 2 ; final File file = new File ( dataDir , BASENAME + i + EXT ) ; if ( ! dataDir . exists ( ) ) { if ( ! dataDir . mkdirs ( ) && ! dataDir . mkdirs ( ) ) { throw new RuntimeException ( "Could not create: " + dataDir ) ; } } final long entryCount ; synchronized ( commitTimeIndex ) { entryCount = SnapshotHelper . write ( commitTimeIndex , file ) ; } snapshotCount ++ ; final long elapsed = System . currentTimeMillis ( ) - begin ; log . warn ( "snapshot: snapshotCount=" + snapshotCount + ", entryCount=" + entryCount + ", file=" + file + ", elapsed=" + elapsed ) ; } catch ( Throwable t ) { log . error ( t . getMessage ( ) , t ) ; return ; } finally { lock . unlock ( ) ; } }
note : anything thrown out of this method will cause the task to no longer be scheduled !
