Coverity Fix for Bad Lock Object

CID 68477: Bad choice of lock object (BAD_LOCK_OBJECT)
- boxed_lock:
Boxing a primitive may or may not return a canonical boxed
representation depending upon the value of the primitive being boxed.
Thus, using a boxed primitive as a lock is dangerous.

Change-Id: Ib993d94bfae6b788b5b56d388fa7a33ec958dee4
Reviewed-on: https://asterix-gerrit.ics.uci.edu/665
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Ian Maxon <imaxon@apache.org>
Reviewed-by: abdullah alamoudi <bamousaa@gmail.com>
diff --git a/asterix-external-data/src/main/java/org/apache/asterix/external/input/HDFSDataSourceFactory.java b/asterix-external-data/src/main/java/org/apache/asterix/external/input/HDFSDataSourceFactory.java
index aa35383..5b3828d 100644
--- a/asterix-external-data/src/main/java/org/apache/asterix/external/input/HDFSDataSourceFactory.java
+++ b/asterix-external-data/src/main/java/org/apache/asterix/external/input/HDFSDataSourceFactory.java
@@ -60,6 +60,7 @@
     protected static Scheduler hdfsScheduler;
     protected static IndexingScheduler indexingScheduler;
     protected static Boolean initialized = false;
+    protected static final Object initLock = new Object();
     protected List<ExternalFile> files;
     protected Map<String, String> configuration;
     protected Class<?> recordClass;
@@ -70,9 +71,7 @@
 
     @Override
     public void configure(Map<String, String> configuration) throws Exception {
-        if (!HDFSDataSourceFactory.initialized) {
-            HDFSDataSourceFactory.initialize();
-        }
+        initialize();
         this.configuration = configuration;
         JobConf conf = HDFSUtils.configureHDFSJobConf(configuration);
         confFactory = new ConfFactory(conf);
@@ -146,11 +145,13 @@
      * HDFS
      */
     private static void initialize() {
-        synchronized (initialized) {
-            if (!initialized) {
-                hdfsScheduler = HDFSUtils.initializeHDFSScheduler();
-                indexingScheduler = HDFSUtils.initializeIndexingHDFSScheduler();
-                initialized = true;
+        if (!initialized) {
+            synchronized (initLock) {
+                if (!initialized) {
+                    hdfsScheduler = HDFSUtils.initializeHDFSScheduler();
+                    indexingScheduler = HDFSUtils.initializeIndexingHDFSScheduler();
+                    initialized = true;
+                }
             }
         }
     }