View | Details | Raw Unified | Return to bug 47921
Collapse All | Expand All

(-)src/core/org/apache/jmeter/threads/JMeterContext.java (+1 lines)
Lines 65-70 Link Here
65
        samplingStarted = false;
65
        samplingStarted = false;
66
        threadNum = 0;
66
        threadNum = 0;
67
        readBuffer = null;
67
        readBuffer = null;
68
        thread = null;
68
    }
69
    }
69
70
70
    /**
71
    /**
(-)src/core/org/apache/jmeter/threads/JMeterThread.java (+32 lines)
Lines 20-28 Link Here
20
20
21
import java.util.ArrayList;
21
import java.util.ArrayList;
22
import java.util.Collection;
22
import java.util.Collection;
23
import java.util.HashSet;
23
import java.util.Iterator;
24
import java.util.Iterator;
24
import java.util.List;
25
import java.util.List;
25
import java.util.ListIterator;
26
import java.util.ListIterator;
27
import java.util.Map;
28
import java.util.Set;
26
29
27
import org.apache.jmeter.assertions.Assertion;
30
import org.apache.jmeter.assertions.Assertion;
28
import org.apache.jmeter.assertions.AssertionResult;
31
import org.apache.jmeter.assertions.AssertionResult;
Lines 123-128 Link Here
123
126
124
    private volatile Sampler currentSampler;
127
    private volatile Sampler currentSampler;
125
128
129
    /**
130
     * Variables backup state at start of run 
131
     */
132
    private JMeterVariables threadVarsBkp;
133
126
    public JMeterThread(HashTree test, JMeterThreadMonitor monitor, ListenerNotifier note) {
134
    public JMeterThread(HashTree test, JMeterThreadMonitor monitor, ListenerNotifier note) {
127
        this.monitor = monitor;
135
        this.monitor = monitor;
128
        threadVars = new JMeterVariables();
136
        threadVars = new JMeterVariables();
Lines 302-307 Link Here
302
            threadFinished();
310
            threadFinished();
303
            monitor.threadFinished(this); // Tell the engine we are done
311
            monitor.threadFinished(this); // Tell the engine we are done
304
            JMeterContextService.removeContext(); // Remove the ThreadLocal entry
312
            JMeterContextService.removeContext(); // Remove the ThreadLocal entry
313
            clearThreadVars();
314
        }
315
    }
316
317
    /**
318
     * Clean all variables that have been added by samplers by coming back to initial set
319
     */
320
    private void clearThreadVars() {
321
        Set<String> keysToKeepSet = new HashSet<String>();
322
        for (Iterator<Map.Entry<String,Object>> iterator = threadVarsBkp.getIterator(); iterator.hasNext();) {
323
            keysToKeepSet.add(iterator.next().getKey());
324
        }
325
        Set<String> keysToRemoveSet = new HashSet<String>();
326
        for (Iterator<Map.Entry<String,Object>> iterator = threadVars.getIterator(); iterator.hasNext();) {
327
            Map.Entry<String,Object> entry = iterator.next();
328
            if(!keysToKeepSet.contains(entry.getKey()))
329
            {
330
                keysToRemoveSet.add(entry.getKey());
331
            }      
332
        }
333
        for (String key : keysToRemoveSet) {
334
            threadVars.remove(key);
305
        }
335
        }
306
    }
336
    }
307
337
Lines 473-478 Link Here
473
     *
503
     *
474
     */
504
     */
475
    private void initRun(JMeterContext threadContext) {
505
    private void initRun(JMeterContext threadContext) {
506
        threadVarsBkp = new JMeterVariables();
507
        threadVarsBkp.putAll(threadVars);
476
        threadContext.setVariables(threadVars);
508
        threadContext.setVariables(threadVars);
477
        threadContext.setThreadNum(getThreadNum());
509
        threadContext.setThreadNum(getThreadNum());
478
        threadContext.getVariables().put(LAST_SAMPLE_OK, TRUE);
510
        threadContext.getVariables().put(LAST_SAMPLE_OK, TRUE);

Return to bug 47921