public void run() {
   while (fsRunning) {
     long period = Math.min(defaultRecheckInterval, timeout);
     try {
       pendingReplicationCheck();
       Thread.sleep(period);
     } catch (InterruptedException ie) {
       FSNamesystem.LOG.debug("PendingReplicationMonitor thread received exception. " + ie);
     }
   }
 }
 /**
  * One replication request for this block has finished. Decrement the number of pending
  * replication requests for this block.
  */
 void remove(Block block) {
   synchronized (pendingReplications) {
     PendingBlockInfo found = pendingReplications.get(block);
     if (found != null) {
       FSNamesystem.LOG.debug("Removing pending replication for block" + block);
       found.decrementReplicas();
       if (found.getNumReplicas() <= 0) {
         pendingReplications.remove(block);
       }
     }
   }
 }
 /** Iterate through all items and detect timed-out items */
 void pendingReplicationCheck() {
   synchronized (pendingReplications) {
     Iterator iter = pendingReplications.entrySet().iterator();
     long now = FSNamesystem.now();
     FSNamesystem.LOG.debug("PendingReplicationMonitor checking Q");
     while (iter.hasNext()) {
       Map.Entry entry = (Map.Entry) iter.next();
       PendingBlockInfo pendingBlock = (PendingBlockInfo) entry.getValue();
       if (now > pendingBlock.getTimeStamp() + timeout) {
         Block block = (Block) entry.getKey();
         synchronized (timedOutItems) {
           timedOutItems.add(block);
         }
         FSNamesystem.LOG.warn("PendingReplicationMonitor timed out block " + block);
         iter.remove();
       }
     }
   }
 }