Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bin/jmeter.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,9 @@ cookies=cookies
# How often to check for shutdown during ramp-up (milliseconds)
#jmeterthread.rampup.granularity=1000

# How often to check for shutdown during timer delay (milliseconds)
#jmeterthread.timer.granularity=1000

#Should JMeter expand the tree when loading a test plan?
# default value is false since JMeter 2.7
#onload.expandtree=false
Expand Down
45 changes: 32 additions & 13 deletions src/core/src/main/java/org/apache/jmeter/threads/JMeterThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public class JMeterThread implements Runnable, Interruptible {
private static final int RAMPUP_GRANULARITY =
JMeterUtils.getPropDefault("jmeterthread.rampup.granularity", 1000); // $NON-NLS-1$

/** How often to check for shutdown during timer delay, default 1000ms */
private static final int TIMER_GRANULARITY =
JMeterUtils.getPropDefault("jmeterthread.timer.granularity", 1000); // $NON-NLS-1$

private static final float TIMER_FACTOR = JMeterUtils.getPropDefault("timer.factor", 1.0f);

private static final TimerService TIMER_SERVICE = TimerService.getInstance();
Expand Down Expand Up @@ -998,21 +1002,36 @@ private void delay(List<? extends Timer> timers) {
totalDelay += delay;
}
if (totalDelay > 0) {
try {
if (scheduler) {
// We reduce pause to ensure end of test is not delayed by a sleep ending after test scheduled end
// See Bug 60049
totalDelay = TIMER_SERVICE.adjustDelay(totalDelay, endTime, false);
if (totalDelay < 0) {
log.debug("The delay would be longer than the scheduled period, so stop thread now.");
running = false;
return;
if (scheduler) {
// We reduce pause to ensure end of test is not delayed by a sleep ending after test scheduled end
// See Bug 60049
totalDelay = TIMER_SERVICE.adjustDelay(totalDelay, endTime, false);
if (totalDelay < 0) {
log.debug("The delay would be longer than the scheduled period, so stop thread now.");
running = false;
return;
}
}
// Use granular sleeps to allow quick response to shutdown
long start = System.currentTimeMillis();
long end = start + totalDelay;
long now;
long pause = TIMER_GRANULARITY;
while (running && (now = System.currentTimeMillis()) < end) {
long togo = end - now;
if (togo < pause) {
pause = togo;
}
try {
TimeUnit.MILLISECONDS.sleep(pause);
} catch (InterruptedException e) {
if (running) { // NOSONAR running may have been changed from another thread
log.warn("The delay timer was interrupted - Loss of delay for {} was {}ms out of {}ms",
threadName, System.currentTimeMillis() - start, totalDelay);
}
Thread.currentThread().interrupt();
break;
}
TimeUnit.MILLISECONDS.sleep(totalDelay);
} catch (InterruptedException e) {
log.warn("The delay timer was interrupted - probably did not wait as long as intended.");
Thread.currentThread().interrupt();
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions xdocs/usermanual/properties_reference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,10 @@ JMETER-SERVER</source>
How often to check for shutdown during ramp-up (milliseconds).<br/>
Defaults to: <code>1000</code>
</property>
<property name="jmeterthread.timer.granularity">
How often to check for shutdown during timer delay (milliseconds).<br/>
Defaults to: <code>1000</code>
</property>
<property name="onload.expandtree">
Should JMeter expand the tree when loading a test plan?<br/>
Default value is <code>false</code> since JMeter 2.7<br/>
Expand Down