Author: thomas.diesler(a)jboss.com
Date: 2009-01-27 05:14:30 -0500 (Tue, 27 Jan 2009)
New Revision: 3723
Modified:
jbpm3/trunk/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/trunk/modules/core/src/main/java/org/jbpm/job/executor/JobExecutor.java
===================================================================
---
jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/JobExecutor.java 2009-01-27
10:06:02 UTC (rev 3722)
+++
jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/JobExecutor.java 2009-01-27
10:14:30 UTC (rev 3723)
@@ -15,8 +15,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;
protected JbpmConfiguration jbpmConfiguration;
@@ -38,53 +38,65 @@
protected static String hostName;
- public synchronized void start() {
- if (!isStarted) {
+ public synchronized void start()
+ {
+ if (!isStarted)
+ {
log.debug("starting thread group '" + name + "'...");
- for (int i = 0; i < nbrOfThreads; i++) {
+ for (int i = 0; i < nbrOfThreads; i++)
+ {
startThread();
}
- lockMonitorThread = new LockMonitorThread(jbpmConfiguration, lockMonitorInterval,
- maxLockTime, lockBufferTime);
+ lockMonitorThread = new LockMonitorThread(jbpmConfiguration, lockMonitorInterval,
maxLockTime, lockBufferTime);
isStarted = true;
}
- else {
+ 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 first. 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 first. 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<Thread> stop() {
+ public synchronized List<Thread> stop()
+ {
List<Thread> stoppedThreads = new ArrayList<Thread>(threads.size());
- if (isStarted) {
+ if (isStarted)
+ {
log.debug("stopping thread group '" + name + "'...");
- for (int i = 0; i < nbrOfThreads; i++) {
+ for (int i = 0; i < nbrOfThreads; i++)
+ {
stoppedThreads.add(stopThread());
}
- lockMonitorThread.deactivate();
+
+ if (lockMonitorThread != null)
+ lockMonitorThread.deactivate();
+
isStarted = false;
}
- else {
+ else
+ {
log.debug("ignoring stop: thread group '" + name + "' not
started");
}
return stoppedThreads;
}
- public void stopAndJoin() throws InterruptedException {
- for (Thread thread : stop()) {
+ public void stopAndJoin() throws InterruptedException
+ {
+ for (Thread thread : stop())
+ {
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);
@@ -92,166 +104,203 @@
thread.start();
}
- protected Thread createThread(String threadName) {
+ protected Thread createThread(String threadName)
+ {
return new JobExecutorThread(threadName, this);
}
- protected String getNextThreadName() {
+ 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 + ":" + getHostAddress() + ":" + index;
}
- private static String getHostAddress() {
- if (hostName == null) {
- try {
+ private static String getHostAddress()
+ {
+ 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);
+ JobExecutorThread thread = (JobExecutorThread)threads.remove(threadName);
log.debug("removing job executor thread '" + threadName +
"'");
thread.deactivate();
return thread;
}
- public Set<Long> getMonitoredJobIds() {
+ public Set<Long> getMonitoredJobIds()
+ {
return new HashSet<Long>(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);
}
- /**
+ /*
* @throws UnsupportedOperationException to prevent invocation
* @deprecated <code>monitoredJobIds</code> is an internal control field
*/
- public void setMonitoredJobIds(Map<String, Long> monitoredJobIds) {
+ public void setMonitoredJobIds(Map<String, Long> monitoredJobIds)
+ {
throw new UnsupportedOperationException();
}
- public int getHistoryMaxSize() {
+ public int getHistoryMaxSize()
+ {
return historyMaxSize;
}
- public void setHistoryMaxSize(int historyMaxSize) {
+ public void setHistoryMaxSize(int historyMaxSize)
+ {
this.historyMaxSize = historyMaxSize;
}
- public int getIdleInterval() {
+ public int getIdleInterval()
+ {
return idleInterval;
}
- public void setIdleInterval(int idleInterval) {
+ public void setIdleInterval(int idleInterval)
+ {
this.idleInterval = idleInterval;
}
- /**
+ /*
* Tells whether this job executor has been {@linkplain #start() started}.
*/
- public boolean isStarted() {
+ public boolean isStarted()
+ {
return isStarted;
}
- /**
+ /*
* @throws UnsupportedOperationException to prevent invocation
* @deprecated <code>isStarted</code> is an internal control field
*/
- public void setStarted(boolean isStarted) {
+ public void setStarted(boolean isStarted)
+ {
throw new UnsupportedOperationException();
}
- public JbpmConfiguration getJbpmConfiguration() {
+ public JbpmConfiguration getJbpmConfiguration()
+ {
return jbpmConfiguration;
}
- public void setJbpmConfiguration(JbpmConfiguration jbpmConfiguration) {
+ public void setJbpmConfiguration(JbpmConfiguration jbpmConfiguration)
+ {
this.jbpmConfiguration = jbpmConfiguration;
}
- public int getMaxIdleInterval() {
+ public int getMaxIdleInterval()
+ {
return maxIdleInterval;
}
- public void setMaxIdleInterval(int maxIdleInterval) {
+ public void setMaxIdleInterval(int maxIdleInterval)
+ {
this.maxIdleInterval = maxIdleInterval;
}
- public String getName() {
+ public String getName()
+ {
return name;
}
- public void setName(String name) {
+ public void setName(String name)
+ {
this.name = name;
}
- public int getSize() {
+ public int getSize()
+ {
return nbrOfThreads;
}
- public void setSize(int nbrOfThreads) {
+ public void setSize(int nbrOfThreads)
+ {
this.nbrOfThreads = nbrOfThreads;
}
- public Map<String, Thread> getThreads() {
+ public Map<String, Thread> getThreads()
+ {
return threads;
}
- /**
+ /*
* @throws UnsupportedOperationException to prevent invocation
* @deprecated <code>thread</code> is an internal control field
*/
- public void setThreads(Map<String, Thread> threads) {
+ public void setThreads(Map<String, Thread> threads)
+ {
throw new UnsupportedOperationException();
}
- public int getMaxLockTime() {
+ public int getMaxLockTime()
+ {
return maxLockTime;
}
- public void setMaxLockTime(int maxLockTime) {
+ public void setMaxLockTime(int maxLockTime)
+ {
this.maxLockTime = maxLockTime;
}
- public int getLockBufferTime() {
+ public int getLockBufferTime()
+ {
return lockBufferTime;
}
- public void setLockBufferTime(int lockBufferTime) {
+ public void setLockBufferTime(int lockBufferTime)
+ {
this.lockBufferTime = lockBufferTime;
}
- public int getLockMonitorInterval() {
+ public int getLockMonitorInterval()
+ {
return lockMonitorInterval;
}
- public void setLockMonitorInterval(int lockMonitorInterval) {
+ public void setLockMonitorInterval(int lockMonitorInterval)
+ {
this.lockMonitorInterval = lockMonitorInterval;
}
- public int getNbrOfThreads() {
+ public int getNbrOfThreads()
+ {
return nbrOfThreads;
}
- public void setNbrOfThreads(int nbrOfThreads) {
+ public void setNbrOfThreads(int nbrOfThreads)
+ {
this.nbrOfThreads = nbrOfThreads;
}
Show replies by date