PHOENIX-6950 PhoenixDriver APIs should unlock closeLock only if thread is able to take lock (#1609)

diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java
index 607f142..e67f0d6 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java
@@ -187,8 +187,8 @@
 
     @Override
     public QueryServices getQueryServices() throws SQLException {
+        lockInterruptibly(LockMode.READ);
         try {
-            lockInterruptibly(LockMode.READ);
             checkClosed();
             // Lazy initialize QueryServices so that we only attempt to create an HBase Configuration
             // object upon the first attempt to connect to any cluster. Otherwise, an attempt will be
@@ -221,8 +221,8 @@
             GLOBAL_FAILED_PHOENIX_CONNECTIONS.increment();
             return null;
         }
+        lockInterruptibly(LockMode.READ);
         try {
-            lockInterruptibly(LockMode.READ);
             checkClosed();
             return createConnection(url, info);
         } catch (SQLException sqlException) {
@@ -240,8 +240,8 @@
     
     @Override
     protected ConnectionQueryServices getConnectionQueryServices(String url, final Properties info) throws SQLException {
+        lockInterruptibly(LockMode.READ);
         try {
-            lockInterruptibly(LockMode.READ);
             checkClosed();
             ConnectionInfo connInfo = ConnectionInfo.create(url);
             SQLException sqlE = null;
@@ -323,8 +323,8 @@
 
     @Override
     public synchronized void close() throws SQLException {
+        lockInterruptibly(LockMode.WRITE);
         try {
-            lockInterruptibly(LockMode.WRITE);
             if (closed) {
                 return;
             }