3737import org .apache .hadoop .io .IOUtils ;
3838import org .apache .hadoop .util .Daemon ;
3939import org .apache .hadoop .util .StringUtils ;
40+ import org .apache .hadoop .util .Time ;
4041
4142/**
4243 * A cache of input stream sockets to Data Node.
@@ -53,7 +54,7 @@ static class SocketAndStreams implements Closeable {
5354 public SocketAndStreams (Socket s , IOStreamPair ioStreams ) {
5455 this .sock = s ;
5556 this .ioStreams = ioStreams ;
56- this .createTime = System . currentTimeMillis ();
57+ this .createTime = Time . monotonicNow ();
5758 }
5859
5960 @ Override
@@ -205,7 +206,7 @@ private synchronized void evictExpired(long expiryPeriod) {
205206 Entry <SocketAddress , SocketAndStreams > entry = iter .next ();
206207 // if oldest socket expired, remove it
207208 if (entry == null ||
208- System . currentTimeMillis () - entry .getValue ().getCreateTime () <
209+ Time . monotonicNow () - entry .getValue ().getCreateTime () <
209210 expiryPeriod ) {
210211 break ;
211212 }
@@ -236,13 +237,13 @@ private synchronized void evictOldest() {
236237 * older than expiryPeriod minutes
237238 */
238239 private void run () throws InterruptedException {
239- for (long lastExpiryTime = System . currentTimeMillis ();
240+ for (long lastExpiryTime = Time . monotonicNow ();
240241 !Thread .interrupted ();
241242 Thread .sleep (expiryPeriod )) {
242- final long elapsed = System . currentTimeMillis () - lastExpiryTime ;
243+ final long elapsed = Time . monotonicNow () - lastExpiryTime ;
243244 if (elapsed >= expiryPeriod ) {
244245 evictExpired (expiryPeriod );
245- lastExpiryTime = System . currentTimeMillis ();
246+ lastExpiryTime = Time . monotonicNow ();
246247 }
247248 }
248249 clear ();
0 commit comments