You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by is...@apache.org on 2016/01/05 16:47:18 UTC
[09/50] [abbrv] stratos git commit: using a shrinking thread pool
instead of a fixed one and adding a thread factory for naming threads
using a shrinking thread pool instead of a fixed one and adding a thread factory for naming threads
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/78ff21c7
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/78ff21c7
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/78ff21c7
Branch: refs/heads/stratos-4.1.x
Commit: 78ff21c7ffc91ed4cab8404e23f331fd19570963
Parents: 503a86f
Author: Isuru Haththotuwa <is...@apache.org>
Authored: Wed Dec 2 19:46:05 2015 +0530
Committer: Isuru Haththotuwa <is...@apache.org>
Committed: Mon Dec 7 18:48:09 2015 +0530
----------------------------------------------------------------------
.../common/threading/StratosThreadFactory.java | 37 ++++++++++++++++++++
.../common/threading/StratosThreadPool.java | 10 +++---
2 files changed, 41 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/78ff21c7/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/threading/StratosThreadFactory.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/threading/StratosThreadFactory.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/threading/StratosThreadFactory.java
new file mode 100644
index 0000000..df3bcae
--- /dev/null
+++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/threading/StratosThreadFactory.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.stratos.common.threading;
+
+import java.util.concurrent.ThreadFactory;
+
+public class StratosThreadFactory implements ThreadFactory {
+
+ private String prefix;
+ private int counter;
+
+ public StratosThreadFactory(String prefix) {
+ this.prefix = prefix;
+ this.counter = 0;
+ }
+
+ public Thread newThread(Runnable r) {
+ return new Thread(r, prefix + "-" + (++counter));
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/78ff21c7/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/threading/StratosThreadPool.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/threading/StratosThreadPool.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/threading/StratosThreadPool.java
index c0ae8ae..b4784a4 100644
--- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/threading/StratosThreadPool.java
+++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/threading/StratosThreadPool.java
@@ -24,10 +24,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.*;
/**
* Utility class for Stratos thread pool
@@ -53,7 +50,8 @@ public class StratosThreadPool {
if (executorService == null) {
synchronized (executorServiceMapLock) {
if (executorService == null) {
- executorService = Executors.newFixedThreadPool(threadPoolSize);
+ executorService = new ThreadPoolExecutor(25, threadPoolSize, 60L, TimeUnit.SECONDS,
+ new LinkedBlockingQueue<Runnable>(), new StratosThreadFactory(identifier));
executorServiceMap.put(identifier, executorService);
log.info(String.format("Thread pool created: [type] Executor Service [id] %s [size] %d", identifier, threadPoolSize));
}
@@ -74,7 +72,7 @@ public class StratosThreadPool {
if (scheduledExecutorService == null) {
synchronized (scheduledServiceMapLock) {
if (scheduledExecutorService == null) {
- scheduledExecutorService = Executors.newScheduledThreadPool(threadPoolSize);
+ scheduledExecutorService = Executors.newScheduledThreadPool(threadPoolSize, new StratosThreadFactory(identifier));
scheduledServiceMap.put(identifier, scheduledExecutorService);
log.info(String.format("Thread pool created: [type] Scheduled Executor Service [id] %s [size] %d",
identifier, threadPoolSize));