Bug 54945

Summary: Add Shutdown Hook to enable trapping kill or CTRL+C signals
Product: JMeter Reporter: Philippe Mouawad <p.mouawad>
Component: MainAssignee: JMeter issues mailing list <issues>
Status: RESOLVED FIXED    
Severity: enhancement CC: p.mouawad
Priority: P2    
Version: 2.9   
Target Milestone: ---   
Hardware: All   
OS: All   
Attachments: Draft of patch

Description Philippe Mouawad 2013-05-09 14:36:29 UTC
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
Comment 1 Philippe Mouawad 2013-05-09 14:56:01 UTC
Created attachment 30267 [details]
Draft of patch

Hello,
Attached is a first proposal of Shutdown Hook implementation.
I had to add a join on StopThread otherwise it can happen exit occurs before thread is started.

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.
Comment 2 Sebb 2013-05-09 15:36:32 UTC
Note: the code in 2.9 and before used autoflush = true
Comment 3 Sebb 2013-05-09 16:13:30 UTC
Note that the shutdown hook is run even if JMeter shuts down normally.
In which case it should not call engine.stop(true).

I wonder if it would be better to implement the shutdown hook in ResultCollector instead.

That might avoid some of the problems?
Comment 4 Philippe Mouawad 2013-05-09 20:33:44 UTC
Nice idea sebb.
I commited this way.

Date: Thu May  9 20:32:55 2013
New Revision: 1480762

URL: http://svn.apache.org/r1480762
Log:
Bug 54945 - Add Shutdown Hook to enable trapping kill or CTRL+C signals
Bugzilla Id: 54945

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/reporters/ResultCollector.java
    jmeter/trunk/xdocs/changes.xml