Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 d68c9d0ed -> 0de62f20b


PHOENIX-4024 Renew lease thread names should be unique across various 
ConnectionQueryServices instances


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/0de62f20
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/0de62f20
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/0de62f20

Branch: refs/heads/4.x-HBase-0.98
Commit: 0de62f20bb879752484c278c85f44d26591c2249
Parents: d68c9d0
Author: Samarth Jain <[email protected]>
Authored: Fri Jul 14 14:25:42 2017 -0700
Committer: Samarth Jain <[email protected]>
Committed: Fri Jul 14 14:25:42 2017 -0700

----------------------------------------------------------------------
 .../query/ConnectionQueryServicesImpl.java      | 24 ++++++++++++++++----
 1 file changed, 19 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/0de62f20/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
index b4274ce..68d92bf 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
@@ -94,6 +94,7 @@ import java.util.concurrent.ThreadLocalRandom;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import javax.annotation.concurrent.GuardedBy;
 
@@ -306,6 +307,11 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
     // List of queues instead of a single queue to provide reduced contention 
via lock striping
     private final List<LinkedBlockingQueue<WeakReference<PhoenixConnection>>> 
connectionQueues;
     private ScheduledExecutorService renewLeaseExecutor;
+    /*
+     * We can have multiple instances of ConnectionQueryServices. By making 
the thread factory
+     * static, renew lease thread names will be unique across them.
+     */
+    private static final ThreadFactory renewLeaseThreadFactory = new 
RenewLeaseThreadFactory(); 
     private final boolean renewLeaseEnabled;
     private final boolean isAutoUpgradeEnabled;
     private final AtomicBoolean upgradeRequired = new AtomicBoolean(false);
@@ -3200,17 +3206,25 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
     
     private void scheduleRenewLeaseTasks() {
         if (isRenewingLeasesEnabled()) {
-            ThreadFactory threadFactory =
-                    new ThreadFactoryBuilder().setDaemon(true)
-                    .setNameFormat("PHOENIX-SCANNER-RENEW-LEASE" + 
"-thread-%s").build();
             renewLeaseExecutor =
-                    Executors.newScheduledThreadPool(renewLeasePoolSize, 
threadFactory);
+                    Executors.newScheduledThreadPool(renewLeasePoolSize, 
renewLeaseThreadFactory);
             for (LinkedBlockingQueue<WeakReference<PhoenixConnection>> q : 
connectionQueues) {
                 renewLeaseExecutor.scheduleAtFixedRate(new RenewLeaseTask(q), 
0,
                         renewLeaseTaskFrequency, TimeUnit.MILLISECONDS);
             }
         }
-    }   
+    }
+    
+    private static class RenewLeaseThreadFactory implements ThreadFactory {
+        private static final AtomicInteger threadNumber = new AtomicInteger(1);
+        private static final String NAME_PREFIX = 
"PHOENIX-SCANNER-RENEW-LEASE-thread-";
+        @Override
+        public Thread newThread(Runnable r) {
+            Thread t = new Thread(r, NAME_PREFIX + 
threadNumber.getAndIncrement());
+            t.setDaemon(true);
+            return t;
+        }
+    }
 
     /**
      * Set IMMUTABLE_ROWS to true for all index tables over immutable tables.

Reply via email to