svn commit: r605371 - in /ofbiz/trunk/framework/service/src/org/ofbiz/service/job: JobInvoker.java JobPoller.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r605371 - in /ofbiz/trunk/framework/service/src/org/ofbiz/service/job: JobInvoker.java JobPoller.java

jaz-3
Author: jaz
Date: Tue Dec 18 16:37:28 2007
New Revision: 605371

URL: http://svn.apache.org/viewvc?rev=605371&view=rev
Log:
fix to the synchronization of threads being removed

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

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobInvoker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobInvoker.java?rev=605371&r1=605370&r2=605371&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobInvoker.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobInvoker.java Tue Dec 18 16:37:28 2007
@@ -97,6 +97,17 @@
     }
 
     /**
+     * Gets the remaining time this thread has before it is killed
+     * @return Time in millis remaining
+     */
+    public long getTimeRemaining() {
+        long now = UtilDateTime.nowTimestamp().getTime();
+        long time = getTime();
+        long ttl = getTTL();
+        return (time + ttl) - now;
+    }
+
+    /**
      * Gets the time when this thread was created.
      * @return Time in milliseconds when this was created.
      */

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=605371&r1=605370&r2=605371&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 Tue Dec 18 16:37:28 2007
@@ -128,8 +128,10 @@
             stateMap.put("threadId", invoker.getThreadId());
             stateMap.put("jobName", invoker.getJobName());
             stateMap.put("serviceName", invoker.getServiceName());
-            stateMap.put("runTime", Long.valueOf(invoker.getCurrentRuntime()));
-            stateMap.put("status", Integer.valueOf(invoker.getCurrentStatus()));
+            stateMap.put("usage", invoker.getUsage());
+            stateMap.put("ttl", invoker.getTimeRemaining());
+            stateMap.put("runTime", invoker.getCurrentRuntime());
+            stateMap.put("status", invoker.getCurrentStatus());
             stateList.add(stateMap);
         }
         return stateList;
@@ -210,13 +212,20 @@
      * Removes a thread from the pool.
      * @param invoker The invoker to remove.
      */
-    public synchronized void removeThread(JobInvoker invoker) {
-        pool.remove(invoker);
-        invoker.stop();
-        if (pool.size() < minThreads()) {
-            for (int i = 0; i < minThreads() - pool.size(); i++) {
-                JobInvoker iv = new JobInvoker(this, invokerWaitTime());
-                pool.add(iv);
+    public void removeThread(JobInvoker invoker) {
+        if (pool != null) {
+            synchronized (pool) {
+                pool.remove(invoker);
+                invoker.stop();
+            }
+        }
+
+        if (pool != null && pool.size() < minThreads()) {
+            synchronized (pool) {
+                for (int i = 0; i < minThreads() - pool.size(); i++) {
+                    JobInvoker iv = new JobInvoker(this, invokerWaitTime());
+                    pool.add(iv);
+                }
             }
         }
     }