Mercurial > hg > jdk9-shenandoah > langtools
changeset 2682:bbd0164f668d
8060715: There is a small race condition in IdleResetSjavac
Summary: Synchronizes on method level instead of variable access level.
Reviewed-by: jfranck
author | alundblad |
---|---|
date | Mon, 27 Oct 2014 14:55:47 +0100 |
parents | 14e1d2a15822 |
children | 478972d90f7b |
files | src/jdk.compiler/share/classes/com/sun/tools/sjavac/server/IdleResetSjavac.java |
diffstat | 1 files changed, 5 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/sjavac/server/IdleResetSjavac.java Fri Oct 24 20:07:08 2014 +0200 +++ b/src/jdk.compiler/share/classes/com/sun/tools/sjavac/server/IdleResetSjavac.java Mon Oct 27 14:55:47 2014 +0100 @@ -30,7 +30,6 @@ import java.util.Set; import java.util.Timer; import java.util.TimerTask; -import java.util.concurrent.atomic.AtomicInteger; /** * An sjavac implementation that keeps track of idleness and shuts down the @@ -47,10 +46,10 @@ public class IdleResetSjavac implements Sjavac { private final Sjavac delegate; - private final AtomicInteger outstandingCalls = new AtomicInteger(); private final Terminable toShutdown; private final Timer idlenessTimer = new Timer(); private final long idleTimeout; + private int outstandingCalls = 0; // Class invariant: idlenessTimerTask != null <-> idlenessTimerTask is scheduled private TimerTask idlenessTimerTask; @@ -94,9 +93,9 @@ } } - private void startCall() { + private synchronized void startCall() { // Was there no outstanding calls before this call? - if (outstandingCalls.incrementAndGet() == 1) { + if (++outstandingCalls == 1) { // Then the timer task must have been scheduled if (idlenessTimerTask == null) throw new IllegalStateException("Idle timeout already cancelled"); @@ -106,8 +105,8 @@ } } - private void endCall() { - if (outstandingCalls.decrementAndGet() == 0) { + private synchronized void endCall() { + if (--outstandingCalls == 0) { // No more outstanding calls. Schedule timeout. scheduleTimeout(); }