[jbpm-commits] JBoss JBPM SVN: r3722 - jbpm3/branches/jbpm-3.2.4.SP/modules/core/src/main/java/org/jbpm/job/executor.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Jan 27 05:06:02 EST 2009


Author: thomas.diesler at jboss.com
Date: 2009-01-27 05:06:02 -0500 (Tue, 27 Jan 2009)
New Revision: 3722

Modified:
   jbpm3/branches/jbpm-3.2.4.SP/modules/core/src/main/java/org/jbpm/job/executor/JobExecutor.java
Log:
[JBPM-1989] Null Pointer Exception in jBPM JobExecutor on server shutdown

Modified: jbpm3/branches/jbpm-3.2.4.SP/modules/core/src/main/java/org/jbpm/job/executor/JobExecutor.java
===================================================================
--- jbpm3/branches/jbpm-3.2.4.SP/modules/core/src/main/java/org/jbpm/job/executor/JobExecutor.java	2009-01-27 08:05:12 UTC (rev 3721)
+++ jbpm3/branches/jbpm-3.2.4.SP/modules/core/src/main/java/org/jbpm/job/executor/JobExecutor.java	2009-01-27 10:06:02 UTC (rev 3722)
@@ -16,7 +16,8 @@
 import org.apache.commons.logging.LogFactory;
 import org.jbpm.JbpmConfiguration;
 
-public class JobExecutor implements Serializable {
+public class JobExecutor implements Serializable
+{
 
   private static final long serialVersionUID = 1L;
 
@@ -39,204 +40,255 @@
 
   protected static String hostName;
 
-  public synchronized void start() {
-    if (! isStarted) {
-      log.debug("starting thread group '"+name+"'...");
-      for (int i=0; i<nbrOfThreads; i++) {
+  public synchronized void start()
+  {
+    if (!isStarted)
+    {
+      log.debug("starting thread group '" + name + "'...");
+      for (int i = 0; i < nbrOfThreads; i++)
+      {
         startThread();
       }
       lockMonitorThread = new LockMonitorThread(jbpmConfiguration, lockMonitorInterval, maxLockTime, lockBufferTime);
       isStarted = true;
-    } else {
-      log.debug("ignoring start: thread group '"+name+"' is already started'");
     }
+    else
+    {
+      log.debug("ignoring start: thread group '" + name + "' is already started'");
+    }
   }
-  
-  /**
-   * signals to all threads in this job executor to stop.  It may be that 
-   *   threads are in the middle of something and they will finish that firts.
-   *   Use {@link #stopAndJoin()} in case you want a method that blocks until 
-   *   all the threads are actually finished.
-   * @return a list of all the stopped threads.  In case no threads were stopped
-   *   an empty list will be returned. 
+
+  /*
+   * signals to all threads in this job executor to stop. It may be that threads are in the middle of something and they will finish that firts. Use {@link
+   * #stopAndJoin()} in case you want a method that blocks until all the threads are actually finished.
+   * @return a list of all the stopped threads. In case no threads were stopped an empty list will be returned.
    */
-  public synchronized List stop() {
+  public synchronized List stop()
+  {
     List stoppedThreads = new ArrayList(threads.size());
-    if (isStarted) {
-      log.debug("stopping thread group '"+name+"'...");
-      for (int i=0; i<nbrOfThreads; i++) {
+    if (isStarted)
+    {
+      log.debug("stopping thread group '" + name + "'...");
+      for (int i = 0; i < nbrOfThreads; i++)
+      {
         stoppedThreads.add(stopThread());
       }
-      lockMonitorThread.deactivate();
+      if (lockMonitorThread != null)
+        lockMonitorThread.deactivate();
       isStarted = false;
-    } else {
-      log.debug("ignoring stop: thread group '"+name+"' not started");
     }
+    else
+    {
+      log.debug("ignoring stop: thread group '" + name + "' not started");
+    }
     return stoppedThreads;
   }
 
-  public void stopAndJoin() throws InterruptedException {
+  public void stopAndJoin() throws InterruptedException
+  {
     Iterator iter = stop().iterator();
-    while (iter.hasNext()) {
-      Thread thread = (Thread) iter.next();
+    while (iter.hasNext())
+    {
+      Thread thread = (Thread)iter.next();
       thread.join();
     }
-    lockMonitorThread.join();
+    if (lockMonitorThread != null)
+      lockMonitorThread.join();
   }
 
-  protected synchronized void startThread() {
+  protected synchronized void startThread()
+  {
     String threadName = getNextThreadName();
     Thread thread = createThread(threadName);
     threads.put(threadName, thread);
-    log.debug("starting new job executor thread '"+threadName+"'");
+    log.debug("starting new job executor thread '" + threadName + "'");
     thread.start();
   }
 
-  protected Thread createThread(String threadName) {
+  protected Thread createThread(String threadName)
+  {
     return new JobExecutorThread(threadName, this, jbpmConfiguration, idleInterval, maxIdleInterval, maxLockTime, historyMaxSize);
   }
 
-  protected String getNextThreadName() {
-    return getThreadName(threads.size()+1);
+  protected String getNextThreadName()
+  {
+    return getThreadName(threads.size() + 1);
   }
-  protected String getLastThreadName() {
+
+  protected String getLastThreadName()
+  {
     return getThreadName(threads.size());
   }
-  
-  private String getThreadName(int index) {
+
+  private String getThreadName(int index)
+  {
     return name + ":" + getHostName() + ":" + index;
   }
 
-  private static String getHostName() {
-    if (hostName == null) {
-      try {
+  private static String getHostName()
+  {
+    if (hostName == null)
+    {
+      try
+      {
         hostName = InetAddress.getLocalHost().getHostAddress();
-      } catch (UnknownHostException e) {
+      }
+      catch (UnknownHostException e)
+      {
         hostName = "127.0.0.1";
-      }      
+      }
     }
     return hostName;
   }
 
-  protected synchronized Thread stopThread() {
+  protected synchronized Thread stopThread()
+  {
     String threadName = getLastThreadName();
-    JobExecutorThread thread = (JobExecutorThread) threads.remove(threadName);
-    log.debug("removing job executor thread '"+threadName+"'");
+    JobExecutorThread thread = (JobExecutorThread)threads.remove(threadName);
+    log.debug("removing job executor thread '" + threadName + "'");
     thread.deactivate();
     return thread;
   }
 
-  public void setMonitoredJobIds(Map monitoredJobIds) {
-		this.monitoredJobIds = monitoredJobIds;
-	}
-  
-  public Set getMonitoredJobIds() {
+  public void setMonitoredJobIds(Map monitoredJobIds)
+  {
+    this.monitoredJobIds = monitoredJobIds;
+  }
+
+  public Set getMonitoredJobIds()
+  {
     return new HashSet(monitoredJobIds.values());
   }
-  
-  public void addMonitoredJobId(String threadName, long jobId) {
+
+  public void addMonitoredJobId(String threadName, long jobId)
+  {
     monitoredJobIds.put(threadName, new Long(jobId));
   }
-  
-  public void removeMonitoredJobId(String threadName) {
+
+  public void removeMonitoredJobId(String threadName)
+  {
     monitoredJobIds.remove(threadName);
   }
 
-  public void setHistoryMaxSize(int historyMaxSize) {
-		this.historyMaxSize = historyMaxSize;
-	}
-  
-  public int getHistoryMaxSize() {
+  public void setHistoryMaxSize(int historyMaxSize)
+  {
+    this.historyMaxSize = historyMaxSize;
+  }
+
+  public int getHistoryMaxSize()
+  {
     return historyMaxSize;
   }
-  
-  public void setIdleInterval(int idleInterval) {
-  	this.idleInterval = idleInterval;
+
+  public void setIdleInterval(int idleInterval)
+  {
+    this.idleInterval = idleInterval;
   }
-  
-  public int getIdleInterval() {
+
+  public int getIdleInterval()
+  {
     return idleInterval;
   }
-  
-  public void setStarted(boolean isStarted) {
-  	this.isStarted = isStarted;
+
+  public void setStarted(boolean isStarted)
+  {
+    this.isStarted = isStarted;
   }
-  
-  public boolean isStarted() {
+
+  public boolean isStarted()
+  {
     return isStarted;
   }
-  
-  public void setJbpmConfiguration(JbpmConfiguration jbpmConfiguration) {
-		this.jbpmConfiguration = jbpmConfiguration;
-	}
-  
-  public JbpmConfiguration getJbpmConfiguration() {
+
+  public void setJbpmConfiguration(JbpmConfiguration jbpmConfiguration)
+  {
+    this.jbpmConfiguration = jbpmConfiguration;
+  }
+
+  public JbpmConfiguration getJbpmConfiguration()
+  {
     return jbpmConfiguration;
   }
-  
-  public void setMaxIdleInterval(int maxIdleInterval) {
-		this.maxIdleInterval = maxIdleInterval;
-	}
-  
-  public int getMaxIdleInterval() {
+
+  public void setMaxIdleInterval(int maxIdleInterval)
+  {
+    this.maxIdleInterval = maxIdleInterval;
+  }
+
+  public int getMaxIdleInterval()
+  {
     return maxIdleInterval;
   }
-  
-  public void setName(String name) {
-  	this.name = name;
+
+  public void setName(String name)
+  {
+    this.name = name;
   }
-  
-  public String getName() {
+
+  public String getName()
+  {
     return name;
   }
-  
-  public void setSize(int nbrOfThreads) {
-  	this.nbrOfThreads = nbrOfThreads;
+
+  public void setSize(int nbrOfThreads)
+  {
+    this.nbrOfThreads = nbrOfThreads;
   }
-  
-  public int getSize() {
+
+  public int getSize()
+  {
     return nbrOfThreads;
   }
-  
-  public void setThreads(Map threads) {
-  	this.threads = threads;
+
+  public void setThreads(Map threads)
+  {
+    this.threads = threads;
   }
-  
-  public Map getThreads() {
+
+  public Map getThreads()
+  {
     return threads;
   }
-  
-  public void setMaxLockTime(int maxLockTime) {
-  	this.maxLockTime = maxLockTime;
+
+  public void setMaxLockTime(int maxLockTime)
+  {
+    this.maxLockTime = maxLockTime;
   }
-  
-  public int getMaxLockTime() {
+
+  public int getMaxLockTime()
+  {
     return maxLockTime;
   }
-  
-  public void setLockBufferTime(int lockBufferTime) {
-  	this.lockBufferTime = lockBufferTime;
+
+  public void setLockBufferTime(int lockBufferTime)
+  {
+    this.lockBufferTime = lockBufferTime;
   }
-  
-  public int getLockBufferTime() {
+
+  public int getLockBufferTime()
+  {
     return lockBufferTime;
   }
-  
-  public void setLockMonitorInterval(int lockMonitorInterval) {
-  	this.lockMonitorInterval = lockMonitorInterval;
+
+  public void setLockMonitorInterval(int lockMonitorInterval)
+  {
+    this.lockMonitorInterval = lockMonitorInterval;
   }
-  
-  public int getLockMonitorInterval() {
+
+  public int getLockMonitorInterval()
+  {
     return lockMonitorInterval;
   }
-  
-  public void setNbrOfThreads(int nbrOfThreads) {
-  	this.nbrOfThreads = nbrOfThreads;
+
+  public void setNbrOfThreads(int nbrOfThreads)
+  {
+    this.nbrOfThreads = nbrOfThreads;
   }
-  
-  public int getNbrOfThreads() {
+
+  public int getNbrOfThreads()
+  {
     return nbrOfThreads;
   }
-  
+
   private static Log log = LogFactory.getLog(JobExecutor.class);
 }




More information about the jbpm-commits mailing list