You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ad...@apache.org on 2013/06/02 16:25:39 UTC
svn commit: r1488715 - in
/ofbiz/trunk/framework/service/src/org/ofbiz/service:
config/model/ThreadPool.java job/JobPoller.java
Author: adrianc
Date: Sun Jun 2 14:25:25 2013
New Revision: 1488715
URL: http://svn.apache.org/r1488715
Log:
Small improvement to the new service config models: move thread pool constants to the ThreadPool model, and initialize instances from the constant values.
Modified:
ofbiz/trunk/framework/service/src/org/ofbiz/service/config/model/ThreadPool.java
ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobPoller.java
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/config/model/ThreadPool.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/config/model/ThreadPool.java?rev=1488715&r1=1488714&r2=1488715&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/config/model/ThreadPool.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/config/model/ThreadPool.java Sun Jun 2 14:25:25 2013
@@ -33,6 +33,14 @@ import org.w3c.dom.Element;
@ThreadSafe
public final class ThreadPool {
+ public static final int FAILED_RETRY_MIN = 30;
+ public static final int MIN_THREADS = 1; // Must be no less than one or the executor will shut down.
+ public static final int MAX_THREADS = 5; // Values higher than 5 might slow things down.
+ public static final int POLL_WAIT = 30000; // Database polling interval - 30 seconds.
+ public static final int PURGE_JOBS_DAYS = 30;
+ public static final int QUEUE_SIZE = 100;
+ public static final int THREAD_TTL = 120000; // Idle thread lifespan - 2 minutes.
+
private final int failedRetryMin;
private final int jobs;
private final int maxThreads;
@@ -52,7 +60,7 @@ public final class ThreadPool {
this.sendToPool = sendToPool;
String purgeJobDays = poolElement.getAttribute("purge-job-days").intern();
if (purgeJobDays.isEmpty()) {
- this.purgeJobDays = 30;
+ this.purgeJobDays = PURGE_JOBS_DAYS;
} else {
try {
this.purgeJobDays = Integer.parseInt(purgeJobDays);
@@ -65,7 +73,7 @@ public final class ThreadPool {
}
String failedRetryMin = poolElement.getAttribute("failed-retry-min").intern();
if (failedRetryMin.isEmpty()) {
- this.failedRetryMin = 30;
+ this.failedRetryMin = FAILED_RETRY_MIN;
} else {
try {
this.failedRetryMin = Integer.parseInt(failedRetryMin);
@@ -78,7 +86,7 @@ public final class ThreadPool {
}
String ttl = poolElement.getAttribute("ttl").intern();
if (ttl.isEmpty()) {
- this.ttl = 120000;
+ this.ttl = THREAD_TTL;
} else {
try {
this.ttl = Integer.parseInt(ttl);
@@ -91,7 +99,7 @@ public final class ThreadPool {
}
String jobs = poolElement.getAttribute("jobs").intern();
if (ttl.isEmpty()) {
- this.jobs = 100;
+ this.jobs = QUEUE_SIZE;
} else {
try {
this.jobs = Integer.parseInt(jobs);
@@ -104,7 +112,7 @@ public final class ThreadPool {
}
String minThreads = poolElement.getAttribute("min-threads").intern();
if (minThreads.isEmpty()) {
- this.minThreads = 1;
+ this.minThreads = MIN_THREADS;
} else {
try {
this.minThreads = Integer.parseInt(minThreads);
@@ -117,7 +125,7 @@ public final class ThreadPool {
}
String maxThreads = poolElement.getAttribute("max-threads").intern();
if (maxThreads.isEmpty()) {
- this.maxThreads = 5;
+ this.maxThreads = MAX_THREADS;
} else {
try {
this.maxThreads = Integer.parseInt(maxThreads);
@@ -131,7 +139,7 @@ public final class ThreadPool {
this.pollEnabled = !"false".equals(poolElement.getAttribute("poll-enabled"));
String pollDbMillis = poolElement.getAttribute("poll-db-millis").intern();
if (pollDbMillis.isEmpty()) {
- this.pollDbMillis = 30000;
+ this.pollDbMillis = POLL_WAIT;
} else {
try {
this.pollDbMillis = Integer.parseInt(pollDbMillis);
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobPoller.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobPoller.java?rev=1488715&r1=1488714&r2=1488715&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobPoller.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobPoller.java Sun Jun 2 14:25:25 2013
@@ -47,11 +47,6 @@ public final class JobPoller {
public static final String module = JobPoller.class.getName();
private static final AtomicInteger created = new AtomicInteger();
- private static final int MIN_THREADS = 1; // Must be no less than one or the executor will shut down.
- private static final int MAX_THREADS = 5; // Values higher than 5 might slow things down.
- private static final int POLL_WAIT = 30000; // Database polling interval - 30 seconds.
- private static final int QUEUE_SIZE = 100;
- private static final long THREAD_TTL = 120000; // Idle thread lifespan - 2 minutes.
private static final ConcurrentHashMap<String, JobManager> jobManagers = new ConcurrentHashMap<String, JobManager>();
// TODO: Put the executor in a cache so Job Poller settings can be changed at run-time.
private static final ThreadPoolExecutor executor = createThreadPoolExecutor();
@@ -71,8 +66,8 @@ public final class JobPoller {
TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(threadPool.getJobs()), new JobInvokerThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
} catch (GenericConfigException e) {
Debug.logError(e, "Exception thrown while getting <thread-pool> model, using default <thread-pool> values: ", module);
- return new ThreadPoolExecutor(MIN_THREADS, MAX_THREADS, THREAD_TTL,
- TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(QUEUE_SIZE), new JobInvokerThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
+ return new ThreadPoolExecutor(ThreadPool.MIN_THREADS, ThreadPool.MAX_THREADS, ThreadPool.THREAD_TTL,
+ TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(ThreadPool.QUEUE_SIZE), new JobInvokerThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
}
}
@@ -82,7 +77,7 @@ public final class JobPoller {
return threadPool.getPollDbMillis();
} catch (GenericConfigException e) {
Debug.logError(e, "Exception thrown while getting <thread-pool> model, using default <thread-pool> values: ", module);
- return POLL_WAIT;
+ return ThreadPool.POLL_WAIT;
}
}