New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Shutdown Hook to enable trapping kill or CTRL+C signals #3120
Comments
@pmouawad (migrated from Bugzilla): Anyway there is still an issue as if shutodwn of threads takes more than jmeterengine.threadstop.wait (ThreadGroup#WAIT_TO_DIE) then it can happen that close will not be called on PrintWriter. Created attachment BUG_54945.patch: Draft of patch BUG_54945.patchIndex: src/core/org/apache/jmeter/JMeter.java
===================================================================
--- src/core/org/apache/jmeter/JMeter.java (revision 1480665)
+++ src/core/org/apache/jmeter/JMeter.java (working copy)
@@ -821,6 +821,7 @@
log.info("Remote engines have been started");
}
startUdpDdaemon(engines);
+ Runtime.getRuntime().addShutdownHook(new Thread(new JMeterShutdownHook(engines)));
} catch (Exception e) {
System.out.println("Error in NonGUIDriver " + e.toString());
log.error("Error in NonGUIDriver", e);
@@ -828,6 +829,28 @@
JOrphanUtils.closeQuietly(reader);
}
}
+
+ private static final class JMeterShutdownHook implements Runnable {
+ private static final Logger log = LoggingManager.getLoggerFor(JMeterShutdownHook.class.getName());
+ private List<JMeterEngine> engines;
+
+ public JMeterShutdownHook(List<JMeterEngine> engines) {
+ this.engines = engines;
+ }
+
+ @Override
+ public void run() {
+ log.warn("Shutdown hook started");
+ for(JMeterEngine engine : engines) {
+ if(engine.isActive()) {
+ log.warn("Shutdown hook is stopping engine:"+engine);
+ engine.stopTest(true);
+ log.warn("Shutdown hook has stopped engine:"+engine);
+ }
+ }
+ log.warn("Shutdown hook ended");
+ }
+ }
/**
* Refactored from AbstractAction.java
Index: src/core/org/apache/jmeter/engine/StandardJMeterEngine.java
===================================================================
--- src/core/org/apache/jmeter/engine/StandardJMeterEngine.java (revision 1480665)
+++ src/core/org/apache/jmeter/engine/StandardJMeterEngine.java (working copy)
@@ -258,6 +258,11 @@
shutdown = !now;
Thread stopThread = new Thread(new StopTest(now));
stopThread.start();
+ try {
+ stopThread.join();
+ } catch (InterruptedException e) {
+ log.warn("Stop thread was interrupted", e);
+ }
}
private class StopTest implements Runnable { |
Sebb (migrated from Bugzilla): |
Sebb (migrated from Bugzilla): I wonder if it would be better to implement the shutdown hook in ResultCollector instead. That might avoid some of the problems? |
@pmouawad (migrated from Bugzilla): Date: Thu May 9 20:32:55 2013 URL: http://svn.apache.org/r1480762 Modified: |
@pmouawad (Bug 54945):
Necessary to avoid losing test data if kill or CTRL+C are called with the following setting (available since JMETER 2.10)
jmeter.save.saveservice.autoflush=false
OS: All
The text was updated successfully, but these errors were encountered: