FELIX-6163: do not use System.currentTimeMillis() to check timeouts
diff --git a/framework/src/main/java/org/apache/felix/framework/util/ThreadGate.java b/framework/src/main/java/org/apache/felix/framework/util/ThreadGate.java
index f9900a3..ff52080 100644
--- a/framework/src/main/java/org/apache/felix/framework/util/ThreadGate.java
+++ b/framework/src/main/java/org/apache/felix/framework/util/ThreadGate.java
@@ -18,6 +18,8 @@
  */
 package org.apache.felix.framework.util;
 
+import java.util.concurrent.TimeUnit;
+
 /**
  * This class implements a simple one-shot gate for threads. The gate
  * starts closed and will block any threads that try to wait on it. Once
@@ -72,14 +74,14 @@
     **/
     public synchronized boolean await(long timeout) throws InterruptedException
     {
-        long start = System.currentTimeMillis();
+        long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
         long remaining = timeout;
         while (!m_open)
         {
             wait(remaining);
             if (timeout > 0)
             {
-                remaining = timeout - (System.currentTimeMillis() - start);
+                remaining = timeout - (TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start);
                 if (remaining <= 0)
                 {
                     break;
diff --git a/framework/src/main/java/org/osgi/util/tracker/ServiceTracker.java b/framework/src/main/java/org/osgi/util/tracker/ServiceTracker.java
index 42c176c..45b1f32 100644
--- a/framework/src/main/java/org/osgi/util/tracker/ServiceTracker.java
+++ b/framework/src/main/java/org/osgi/util/tracker/ServiceTracker.java
@@ -20,6 +20,7 @@
 import java.util.Collections;
 import java.util.SortedMap;
 import java.util.TreeMap;
+import java.util.concurrent.TimeUnit;
 
 import org.osgi.annotation.versioning.ConsumerType;
 import org.osgi.framework.AllServiceListener;
@@ -493,7 +494,7 @@
 			return object;
 		}
 
-		final long endTime = (timeout == 0) ? 0 : (System.currentTimeMillis() + timeout);
+		final long endTime = (timeout == 0) ? 0 : (TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) + timeout);
 		do {
 			final Tracked t = tracked();
 			if (t == null) { /* if ServiceTracker is not open */
@@ -506,7 +507,7 @@
 			}
 			object = getService();
 			if (endTime > 0) { // if we have a timeout
-				timeout = endTime - System.currentTimeMillis();
+				timeout = endTime - TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
 				if (timeout <= 0) { // that has expired
 					break;
 				}