From: Scott M S. <st...@us...> - 2004-12-30 05:54:10
|
User: starksm Date: 04/12/29 21:54:02 Modified: src/main/org/jboss/mx/util Tag: Branch_4_0 SchedulableRunnable.java Log: Change the nextRun instance variable to a SynchronizedLong and remove the synchronization on the getNextRun() accessor to avoid deadlock when a scheduler is waiting on runnables and a runnable is trying to null out its scheduler due to a monitor being stopped. An example stack trace for this scenario is: Thread "Thread-0"@793 in group "main" status: MONITOR waitOutstanding():186, org.jboss.mx.util.RunnableScheduler run():93, org.jboss.mx.util.RunnableScheduler run():479, java.lang.Thread Thread "main"@1 in group "main" status: MONITOR setScheduler():126, org.jboss.mx.util.SchedulableRunnable stop():208, javax.management.monitor.StringMonitor ... stopMonitorService():399, org.jboss.test.jbossmx.compliance.monitor.BasicTestCase testStringBothNotification():235, org.jboss.test.jbossmx.compliance.monitor.BasicTestCase Revision Changes Path No revision No revision 1.3.6.1 +7 -7 jmx/src/main/org/jboss/mx/util/SchedulableRunnable.java Index: SchedulableRunnable.java =================================================================== RCS file: /cvsroot/jboss/jmx/src/main/org/jboss/mx/util/SchedulableRunnable.java,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -r1.3 -r1.3.6.1 --- SchedulableRunnable.java 26 Feb 2004 22:40:28 -0000 1.3 +++ SchedulableRunnable.java 30 Dec 2004 05:54:02 -0000 1.3.6.1 @@ -6,10 +6,9 @@ */ package org.jboss.mx.util; +import EDU.oswego.cs.dl.util.concurrent.SynchronizedLong; import org.jboss.logging.Logger; -import javax.management.timer.Timer; - /** * A schedulable runnable.<p> * @@ -22,7 +21,8 @@ * @see RunnableScheduler * * @author <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>. - * @version $Revision: 1.3 $ + * @author Sco...@jb... + * @version $Revision: 1.3.6.1 $ */ public abstract class SchedulableRunnable implements Comparable, Runnable @@ -40,7 +40,7 @@ /** * The next run timestamp */ - private long nextRun; + private SynchronizedLong nextRun = new SynchronizedLong(0); /** * The current scheduler @@ -83,7 +83,7 @@ */ public long getNextRun() { - return nextRun; + return nextRun.get(); } /** @@ -101,7 +101,7 @@ scheduler.remove(this); // Set the new run time - this.nextRun = nextRun; + this.nextRun.set(nextRun); // If we are not running, add it to the scheduler otherwise // remember we want adding back @@ -185,7 +185,7 @@ public int compareTo(Object o) { SchedulableRunnable other = (SchedulableRunnable) o; - long temp = this.nextRun - other.nextRun; + long temp = this.nextRun.get() - other.nextRun.get(); if (temp < 0) return -1; if (temp > 0) |