ofbiz-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adri...@apache.org
Subject svn commit: r1488736 - /ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobPoller.java
Date Sun, 02 Jun 2013 16:25:09 GMT
Author: adrianc
Date: Sun Jun  2 16:25:09 2013
New Revision: 1488736

URL: http://svn.apache.org/r1488736
Log:
JobPoller improvement - make it a ServiceConfigListener so service config file changes can
be made at run-time. One <thread-pool> attribute doesn't get updated: "jobs" (the queue
size) - which would require creating a new ThreadPoolExecutor instance, and that would require
a lot of complicated synchronization code.

Modified:
    ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobPoller.java

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=1488736&r1=1488735&r2=1488736&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 16:25:09
2013
@@ -38,17 +38,18 @@ import org.ofbiz.base.start.Start;
 import org.ofbiz.base.util.Assert;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.service.config.ServiceConfigUtil;
+import org.ofbiz.service.config.ServiceConfigListener;
+import org.ofbiz.service.config.model.ServiceConfig;
 import org.ofbiz.service.config.model.ThreadPool;
 
 /**
  * Job poller. Queues and runs jobs.
  */
-public final class JobPoller {
+public final class JobPoller implements ServiceConfigListener {
 
     public static final String module = JobPoller.class.getName();
     private static final AtomicInteger created = new AtomicInteger();
     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();
     private static final JobPoller instance = new JobPoller();
 
@@ -104,6 +105,7 @@ public final class JobPoller {
         } else {
             jobManagerPollerThread = null;
         }
+        ServiceConfigUtil.registerServiceConfigListener(this);
     }
 
     /**
@@ -139,6 +141,16 @@ public final class JobPoller {
         return poolState;
     }
 
+    @Override
+    public void onServiceConfigChange(ServiceConfig serviceConfig) {
+        if (!executor.isShutdown()) {
+            ThreadPool threadPool = serviceConfig.getServiceEngine(ServiceConfigUtil.engine).getThreadPool();
+            executor.setCorePoolSize(threadPool.getMinThreads());
+            executor.setMaximumPoolSize(threadPool.getMaxThreads());
+            executor.setKeepAliveTime(threadPool.getTtl(), TimeUnit.MILLISECONDS);
+        }
+    }
+
     private boolean pollEnabled() {
         String enabled = ServiceConfigUtil.getElementAttr("thread-pool", "poll-enabled");
         return !"false".equalsIgnoreCase(enabled);



Mime
View raw message