Author: alex.guizar(a)jboss.com
Date: 2010-01-13 13:55:43 -0500 (Wed, 13 Jan 2010)
New Revision: 6076
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/job/executor/JobExecutor.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/job/executor/LockMonitorThread.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/log4j.xml
Log:
JBPM-2691: refine job executor thread restoration code by exploiting
ThreadGroup.uncaughtException
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/job/executor/JobExecutor.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/job/executor/JobExecutor.java 2010-01-13
14:52:06 UTC (rev 6075)
+++
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/job/executor/JobExecutor.java 2010-01-13
18:55:43 UTC (rev 6076)
@@ -3,7 +3,7 @@
import java.io.Serializable;
import java.net.InetAddress;
import java.net.UnknownHostException;
-import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -25,7 +25,7 @@
protected JbpmConfiguration jbpmConfiguration;
protected String name;
protected int nbrOfThreads;
- private int retries = 1;
+ private int retries = 1;
protected int idleInterval;
protected int maxIdleInterval;
/** @deprecated this field was never used */
@@ -35,6 +35,7 @@
protected int lockMonitorInterval;
protected int lockBufferTime;
+ private ThreadGroup threadGroup;
protected Map threads = new HashMap();
protected LockMonitorThread lockMonitorThread;
protected Map monitoredJobIds = new Hashtable();
@@ -49,9 +50,7 @@
for (int i = 0; i < nbrOfThreads; i++) {
startThread();
}
- lockMonitorThread =
- new LockMonitorThread(getLockMonitorThreadName(), this);
- lockMonitorThread.start();
+ startLockMonitorThread();
isStarted = true;
}
else {
@@ -69,23 +68,25 @@
* empty list will be returned.
*/
public synchronized List stop() {
- List stoppedThreads;
- if (isStarted) {
- log.debug("stopping job executor '" + name + '\'');
- isStarted = false;
+ if (!isStarted) {
+ log.debug("ignoring stop: job executor '" + name + "' not
started");
+ return Collections.EMPTY_LIST;
+ }
- stoppedThreads = new ArrayList(threads.size());
- for (int i = 0; i < nbrOfThreads; i++) {
- stoppedThreads.add(stopThread());
- }
+ log.debug("stopping job executor '" + name + '\'');
+ isStarted = false;
- if (lockMonitorThread != null) lockMonitorThread.deactivate();
+ Thread[] stoppedThreads = new Thread[threads.size()];
+ for (int i = 0; i < nbrOfThreads; i++) {
+ stoppedThreads[i] = stopThread();
}
- else {
- log.debug("ignoring stop: job executor '" + name + "' not
started");
- stoppedThreads = Collections.EMPTY_LIST;
+
+ if (lockMonitorThread != null) {
+ lockMonitorThread.deactivate();
+ lockMonitorThread = null;
}
- return stoppedThreads;
+
+ return Arrays.asList(stoppedThreads);
}
public void stopAndJoin() throws InterruptedException {
@@ -98,19 +99,36 @@
}
public void ensureThreadsAreActive() {
- List deadThreads = new ArrayList();
+ String[] deceasedNames = new String[threads.size()];
+ int deathToll = 0;
for (Iterator i = threads.values().iterator(); i.hasNext();) {
Thread thread = (Thread) i.next();
if (!thread.isAlive()) {
- deadThreads.add(thread.getName());
- i.remove();
+ deceasedNames[deathToll++] = thread.getName();
}
}
- for (int i = 0; i < deadThreads.size(); i++) {
- startThread((String) deadThreads.get(i));
+ for (int i = 0; i < deathToll; i++) {
+ startThread(deceasedNames[i]);
}
}
+ synchronized ThreadGroup getThreadGroup() {
+ if (threadGroup == null) {
+ threadGroup = new ThreadGroup(name) {
+ public void uncaughtException(Thread thread, Throwable throwable) {
+ if (thread instanceof JobExecutorThread) {
+ startThread(thread.getName());
+ }
+ else if (thread instanceof LockMonitorThread) {
+ startLockMonitorThread();
+ }
+ super.uncaughtException(thread, throwable);
+ }
+ };
+ }
+ return threadGroup;
+ }
+
protected void startThread() {
startThread(getNextThreadName());
}
@@ -139,6 +157,11 @@
return name + ":" + getHostAddress() + ":" + index;
}
+ private void startLockMonitorThread() {
+ lockMonitorThread = new LockMonitorThread(getLockMonitorThreadName(), this);
+ lockMonitorThread.start();
+ }
+
private String getLockMonitorThreadName() {
return name + ':' + LockMonitorThread.DEFAULT_NAME + '@' +
getHostAddress();
}
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java 2010-01-13
14:52:06 UTC (rev 6075)
+++
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java 2010-01-13
18:55:43 UTC (rev 6076)
@@ -30,7 +30,7 @@
volatile boolean isActive = true;
public JobExecutorThread(String name, JobExecutor jobExecutor) {
- super(name);
+ super(jobExecutor.getThreadGroup(), name);
this.jobExecutor = jobExecutor;
jbpmConfiguration = jobExecutor.getJbpmConfiguration();
@@ -45,8 +45,9 @@
public JobExecutorThread(String name, JobExecutor jobExecutor,
JbpmConfiguration jbpmConfiguration, int idleInterval,
int maxIdleInterval, long maxLockTime, int maxHistory) {
- super(name);
+ super(jobExecutor.getThreadGroup(), name);
this.jobExecutor = jobExecutor;
+
this.jbpmConfiguration = jbpmConfiguration;
this.idleInterval = idleInterval;
this.maxIdleInterval = maxIdleInterval;
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/job/executor/LockMonitorThread.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/job/executor/LockMonitorThread.java 2010-01-13
14:52:06 UTC (rev 6075)
+++
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/job/executor/LockMonitorThread.java 2010-01-13
18:55:43 UTC (rev 6076)
@@ -29,7 +29,7 @@
}
public LockMonitorThread(String name, JobExecutor jobExecutor) {
- super(name);
+ super(jobExecutor.getThreadGroup(), name);
jbpmConfiguration = jobExecutor.getJbpmConfiguration();
lockMonitorInterval = jobExecutor.getLockMonitorInterval();
maxLockTime = jobExecutor.getMaxLockTime();
@@ -49,7 +49,6 @@
while (isActive) {
try {
unlockOverdueJobs();
- jbpmConfiguration.getJobExecutor().ensureThreadsAreActive();
}
catch (RuntimeException e) {
log.error("exception in " + getName(), e);
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/log4j.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/log4j.xml 2010-01-13
14:52:06 UTC (rev 6075)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/log4j.xml 2010-01-13
18:55:43 UTC (rev 6076)
@@ -36,6 +36,10 @@
<priority value="INFO" />
</category>
+ <category
name="org.hibernate.engine.StatefulPersistenceContext.ProxyWarnLog">
+ <priority value="ERROR" />
+ </category>
+
<!--
<category name="org.hibernate.SQL">
<priority value="DEBUG" />
Show replies by date