From 814cd5ba4bbe19cfca4e545aa445b833bbacd7cd Mon Sep 17 00:00:00 2001 From: kohsuke Date: Mon, 18 Aug 2008 21:51:35 +0000 Subject: [PATCH] [FIXED HUDSON-2230] Fixed IllegalMonitorStateException. In 1.249. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@11604 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/model/Build.java | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/hudson/model/Build.java b/core/src/main/java/hudson/model/Build.java index 65e00b452f..9b37d4e0f8 100644 --- a/core/src/main/java/hudson/model/Build.java +++ b/core/src/main/java/hudson/model/Build.java @@ -24,6 +24,11 @@ import java.util.logging.Logger; public abstract class Build

,B extends Build> extends AbstractBuild { + /** + * If the build required a lock, remember it so that we can release it. + */ + private transient ReentrantLock buildLock; + /** * Creates a new build. */ @@ -48,16 +53,16 @@ public abstract class Build

,B extends Build> SCMTrigger t = (SCMTrigger)project.getTriggers().get(SCMTrigger.DESCRIPTOR); if(t!=null) { // acquire the lock - ReentrantLock lock = t.getLock(); - synchronized(lock) { + buildLock = t.getLock(); + synchronized(buildLock) { try { - if(lock.isLocked()) { + if(buildLock.isLocked()) { long time = System.currentTimeMillis(); LOGGER.info("Waiting for the polling of "+getParent()+" to complete"); - lock.lockInterruptibly(); + buildLock.lockInterruptibly(); LOGGER.info("Polling completed. Waited "+(System.currentTimeMillis()-time)+"ms"); } else - lock.lockInterruptibly(); + buildLock.lockInterruptibly(); } catch (InterruptedException e) { // handle the interrupt later Thread.currentThread().interrupt(); @@ -69,9 +74,8 @@ public abstract class Build

,B extends Build> @Override protected void onEndBuilding() { super.onEndBuilding(); - SCMTrigger t = (SCMTrigger)project.getTriggers().get(SCMTrigger.DESCRIPTOR); - if(t!=null) - t.getLock().unlock(); + if(buildLock!=null) + buildLock.unlock(); } //