Remove expensive uses of Calendar.getInstance() 81/25981/3
authorStephen Kitt <skitt@redhat.com>
Tue, 25 Aug 2015 16:07:50 +0000 (18:07 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 24 Sep 2015 11:36:48 +0000 (11:36 +0000)
nanoTime() is used instead of currentTimeMillis() to avoid issues with
leap seconds.

Change-Id: Idbfcd994424c91a384c47fe0ad12bc6a7ea33972
Signed-off-by: Stephen Kitt <skitt@redhat.com>
opendaylight/md-sal/mdsal-it-base/src/main/java/org/opendaylight/controller/mdsal/it/base/AbstractMdsalTestBase.java
opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLAdapter.java

index 0bec30d4740a6e53614aac97a18e8ea2b80185a9..843cfced1fdc1f250bdd716f2d7b71c8549eaa74 100644 (file)
@@ -11,8 +11,6 @@ package org.opendaylight.controller.mdsal.it.base;
 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
 import static org.ops4j.pax.exam.CoreOptions.composite;
 
-import java.util.Calendar;
-
 import javax.inject.Inject;
 
 import org.junit.Before;
@@ -50,7 +48,7 @@ public abstract class AbstractMdsalTestBase extends AbstractConfigTestBase imple
     @Before
     public void setup() throws Exception {
         super.setup();
-        Calendar start = Calendar.getInstance();
+        long start = System.nanoTime();
         ServiceReference<BindingAwareBroker> serviceReference = context.getServiceReference(BindingAwareBroker.class);
         if(serviceReference == null) {
             throw new RuntimeException("BindingAwareBroker not found");
@@ -59,10 +57,10 @@ public abstract class AbstractMdsalTestBase extends AbstractConfigTestBase imple
         broker.registerProvider(this);
         for(int i=0;i<REGISTRATION_TIMEOUT;i++) {
             if(session !=null) {
-                Calendar stop = Calendar.getInstance();
-                LOG.info("Registered session {} with the MD-SAL after {} ms",
+                long stop = System.nanoTime();
+                LOG.info("Registered session {} with the MD-SAL after {} ns",
                         session,
-                        stop.getTimeInMillis() - start.getTimeInMillis());
+                        stop - start);
                 return;
             } else {
                 Thread.sleep(1);
index 91b34b85e51301b876165b8372c0d1903ea58537..818f4ebfbbeb1929d0d74df8e144e868384bfd43 100644 (file)
@@ -15,7 +15,7 @@ import java.net.ServerSocket;
 import java.net.Socket;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Calendar;
+import java.util.Date;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -112,7 +112,7 @@ public class XSQLAdapter extends Thread implements SchemaContextListener {
                     }
                 }
             }
-            l.print(Calendar.getInstance().getTime());
+            l.print(new Date());
             l.print(" - ");
             l.println(str);
         } catch (Exception err) {
@@ -130,7 +130,7 @@ public class XSQLAdapter extends Thread implements SchemaContextListener {
                     }
                 }
             }
-            l.print(Calendar.getInstance().getTime());
+            l.print(new Date());
             l.print(" - ");
             e.printStackTrace(l);
         } catch (Exception err) {