Author: ron.sigal(a)jboss.com
Date: 2008-11-29 23:19:39 -0500 (Sat, 29 Nov 2008)
New Revision: 4754
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/ConnectionValidator.java
Log:
JBREM-1070: Made some changes to synchronization on "lock" variable.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/ConnectionValidator.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/ConnectionValidator.java 2008-11-30
04:19:02 UTC (rev 4753)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/ConnectionValidator.java 2008-11-30
04:19:39 UTC (rev 4754)
@@ -228,6 +228,7 @@
private ClientInvoker clientInvoker;
private Object lock = new Object();
private Object notificationLock = new Object();
+ private boolean started;
private volatile boolean stopped;
private String invokerSessionId;
private boolean tieToLease = true;
@@ -283,51 +284,54 @@
*/
public void run()
{
- synchronized (lock) {
- if (timer == null)
+ synchronized (lock)
+ {
+ if (!started)
{
throw new IllegalStateException(
ConnectionValidator.class.getName() + ".run() should not be "
+
"called directly; use " + ConnectionValidator.class.getName()
+
".addConnectionListener() instead.");
}
- }
-
- TimerTask tt = new WaitOnConnectionCheckTimerTask();
+
+ if (stopped)
+ {
+ return;
+ }
+
+ TimerTask tt = new WaitOnConnectionCheckTimerTask();
- try
- {
- timer.schedule(tt, 0);
+ try
+ {
+ timer.schedule(tt, 0);
+ }
+ catch (IllegalStateException e)
+ {
+ log.debug("Unable to schedule TimerTask on existing Timer", e);
+ timer = new Timer(true);
+ timer.schedule(tt, 0);
+ }
}
- catch (IllegalStateException e)
- {
- log.debug("Unable to schedule TimerTask on existing Timer", e);
- timer = new Timer(true);
- timer.schedule(tt, 0);
- }
try
{
- synchronized(lock)
+ if(!stopped)
{
- if(!stopped)
+ isValid = false;
+
+ if (tieToLease && client.getLeasePeriod() > 0)
{
- isValid = false;
-
- if (tieToLease && client.getLeasePeriod() > 0)
+ if (trace)
{
- if (trace)
- {
- log.trace(this + " sending PING tied to lease");
- }
- isValid = doCheckConnectionWithLease();
+ log.trace(this + " sending PING tied to lease");
}
- else
- {
- if (trace) { log.trace(this + " pinging ..."); }
- isValid = doCheckConnectionWithoutLease();
- }
+ isValid = doCheckConnectionWithLease();
}
+ else
+ {
+ if (trace) { log.trace(this + " pinging ..."); }
+ isValid = doCheckConnectionWithoutLease();
+ }
}
}
catch (Throwable thr)
@@ -523,7 +527,7 @@
}
TimerUtil.schedule(this, pingPeriod);
- stopped = false;
+ started = true;
timer = new Timer(true);
log.debug(this + " started");
}
@@ -622,6 +626,10 @@
final Throwable t = thr;
synchronized (lock)
{
+ if (stopped)
+ {
+ return;
+ }
ListIterator itr = listeners.listIterator();
while (itr.hasNext())
{