This documentation relates to QuickBuild 2.1.x
You are viewing a different version of QuickBuild. Please refer to the listing to choose another version.
Some grid nodes may have limited resource, and can only run limited number of concurrent jobs.
h1. Demonstration
[Project1|http://demo.pmease.com/build/76.latest], [project2|http://demo.pmease.com/build/77.latest], and [project3|http://demo.pmease.com/build/78.latest] are used to demonstrate the case where server node only permits to run two concurrent jobs.
# Trigger project1
# Trigger project2 right after you triggered project1, without waiting for its finish.
# Trigger project3 right after you triggered project2, without waiting for its finish.
# Switch to build log of these three configurations. You will see that project1 and project2 are actually doing the job (printing the message _do my job with acquired resource..._), while project3 is waiting for the resource (printing the message _Executing pre-execute script..._).
# After project1 or project2 finishes (in about 1 minute), project3 will acquire the resource and do the job.
h1. Resolution
Switch to [master step definition|http://demo.pmease.com/setting/steps/execution/75] of these three projects:
# the pre-execute script is defined as:
{code}
groovy:
node.getResource("resource1", new java.util.concurrent.Semaphore(2)).acquire();
{code}
This tells QuickBuild to get node resource named _resource1_, and create the resource as a Java semaphore object with two permits if it does not already exist. And then acquire the resource by calling its _acquire_ method before executing the step.
# the post-execute script is defined as:
{code}
groovy:node.getResource("resource1").release();
{code}
This tells QuickBuild to release the node resource named _resource1_ before finishing the step.