Buggy code:
pause ( ( 10 * ( countStillActiveThreads ( ) ) ) ) ; boolean stopped = verifyThreadsStopped ( ) ; if ( ! stopped ) { if ( JMeter . isNonGUI ( ) ) { StandardJMeterEngine . log . fatalError ( JMeterUtils . getResString ( "stopping_test_failed" ) ) ; if ( StandardJMeterEngine . SYSTEM_EXIT_ON_STOP_FAIL ) { StandardJMeterEngine . log . fatalError ( "Exitting" ) ; System . out . println ( "Fatal<seq2seq4repair_space>error,<seq2seq4repair_space>could<seq2seq4repair_space>not<seq2seq4repair_space>stop<seq2seq4repair_space>test,<seq2seq4repair_space>exitting" ) ; System . exit ( 1 ) ; } else { System . out . println ( "Fatal<seq2seq4repair_space>error,<seq2seq4repair_space>could<seq2seq4repair_space>not<seq2seq4repair_space>stop<seq2seq4repair_space>test" ) ; } } else { JMeterUtils . reportErrorToUser ( JMeterUtils . getResString ( "stopping_test_failed" ) , JMeterUtils . getResString ( "stopping_test_title" ) ) ; } } } else { stopAllThreadGroups ( ) ; } } } public void run ( ) { StandardJMeterEngine . log . info ( "Running<seq2seq4repair_space>the<seq2seq4repair_space>test!" ) ; running = true ; JMeterContextService . startTest ( ) ; try { PreCompiler compiler = new PreCompiler ( ) ; test . traverse ( compiler ) ; } catch ( RuntimeException e ) { StandardJMeterEngine . log . error ( "Error<seq2seq4repair_space>occurred<seq2seq4repair_space>compiling<seq2seq4repair_space>the<seq2seq4repair_space>tree:" , e ) ; JMeterUtils . reportErrorToUser ( "Error<seq2seq4repair_space>occurred<seq2seq4repair_space>compiling<seq2seq4repair_space>the<seq2seq4repair_space>tree:<seq2seq4repair_space>-<seq2seq4repair_space>see<seq2seq4repair_space>log<seq2seq4repair_space>file" ) ; return ; } SearchByClass < TestStateListener > testListeners = new SearchByClass < TestStateListener > ( TestStateListener . class ) ; test . traverse ( testListeners ) ; testListeners . getSearchResults ( ) . addAll ( StandardJMeterEngine . testList ) ; StandardJMeterEngine . testList . clear ( ) ; if ( ! ( StandardJMeterEngine . startListenersLater ) ) { notifyTestListenersOfStart ( testListeners ) ; } test . traverse ( new TurnElementsOn ( ) ) ; if ( StandardJMeterEngine . startListenersLater ) { notifyTestListenersOfStart ( testListeners ) ; } List < ? > testLevelElements = new LinkedList < Object > ( test . list ( test . getArray ( ) [ 0 ] ) ) ; removeThreadGroups ( testLevelElements ) ; SearchByClass < SetupThreadGroup > setupSearcher = new SearchByClass < SetupThreadGroup > ( SetupThreadGroup . class ) ; SearchByClass < AbstractThreadGroup > searcher = new SearchByClass < AbstractThreadGroup > ( AbstractThreadGroup . class ) ; SearchByClass < PostThreadGroup > postSearcher = new SearchByClass < PostThreadGroup > ( PostThreadGroup . class ) ; test . traverse ( setupSearcher ) ; test . traverse ( searcher ) ; test . traverse ( postSearcher ) ; TestCompiler . initialize ( ) ; Iterator < SetupThreadGroup > setupIter = setupSearcher . getSearchResults ( ) . iterator ( ) ; Iterator < AbstractThreadGroup > iter = searcher . getSearchResults ( ) . iterator ( ) ; Iterator < PostThreadGroup > postIter = postSearcher . getSearchResults ( ) . iterator ( ) ; ListenerNotifier notifier = new ListenerNotifier ( ) ; int groupCount = 0 ; JMeterContextService . clearTotalThreads ( ) ; if ( setupIter . hasNext ( ) ) { StandardJMeterEngine . log . info ( "Starting<seq2seq4repair_space>setUp<seq2seq4repair_space>thread<seq2seq4repair_space>groups" ) ; while ( ( running ) && ( setupIter . hasNext ( ) ) ) { AbstractThreadGroup group = setupIter . next ( ) ; groupCount ++ ; String groupName = group . getName ( ) ; StandardJMeterEngine . log . info ( ( ( ( "Starting<seq2seq4repair_space>setUp<seq2seq4repair_space>ThreadGroup:<seq2seq4repair_space>" + groupCount ) + "<seq2seq4repair_space>:<seq2seq4repair_space>" ) + groupName ) ) ; startThreadGroup ( group , groupCount , setupSearcher , testLevelElements , notifier ) ; if ( ( serialized ) && ( setupIter . hasNext ( ) ) ) { StandardJMeterEngine . log . info ( ( ( "Waiting<seq2seq4repair_space>for<seq2seq4repair_space>setup<seq2seq4repair_space>thread<seq2seq4repair_space>group:<seq2seq4repair_space>" + groupName ) + "<seq2seq4repair_space>to<seq2seq4repair_space>finish<seq2seq4repair_space>before<seq2seq4repair_space>starting<seq2seq4repair_space>next<seq2seq4repair_space>setup<seq2seq4repair_space>group" ) ) ; group . waitThreadsStopped ( ) ; } } StandardJMeterEngine . log . info ( "Waiting<seq2seq4repair_space>for<seq2seq4repair_space>all<seq2seq4repair_space>setup<seq2seq4repair_space>thread<seq2seq4repair_space>groups<seq2seq4repair_space>to<seq2seq4repair_space>exit" ) ; waitThreadsStopped ( ) ; StandardJMeterEngine . log . info ( "All<seq2seq4repair_space>Setup<seq2seq4repair_space>Threads<seq2seq4repair_space>have<seq2seq4repair_space>ended" ) ; groupCount = 0 ; JMeterContextService . clearTotalThreads ( ) ; } groups . clear ( ) ; <START_BUG> System . gc ( ) ; <END_BUG> JMeterContextService . getContext ( ) . setSamplingStarted ( true ) ; boolean mainGroups = running ; while ( ( running ) && ( iter . hasNext ( ) ) ) { AbstractThreadGroup group = iter . next ( ) ; if ( group instanceof SetupThreadGroup ) continue ; if ( group instanceof PostThreadGroup ) continue ; groupCount ++ ; String groupName = group . getName ( ) ; StandardJMeterEngine . log . info ( ( ( ( "Starting<seq2seq4repair_space>ThreadGroup:<seq2seq4repair_space>" + groupCount ) + "<seq2seq4repair_space>:<seq2seq4repair_space>" ) + groupName ) ) ; startThreadGroup ( group , groupCount , searcher , testLevelElements , notifier ) ; if ( ( serialized ) && ( iter . hasNext ( ) ) ) { StandardJMeterEngine . log . info ( ( ( "Waiting<seq2seq4repair_space>for<seq2seq4repair_space>thread<seq2seq4repair_space>group:<seq2seq4repair_space>" + groupName ) + "<seq2seq4repair_space>to<seq2seq4repair_space>finish<seq2seq4repair_space>before<seq2seq4repair_space>starting<seq2seq4repair_space>next<seq2seq4repair_space>group" ) ) ; group . waitThreadsStopped ( ) ; } } if ( groupCount == 0 ) { StandardJMeterEngine . log . info ( "No<seq2seq4repair_space>enabled<seq2seq4repair_space>thread<seq2seq4repair_space>groups<seq2seq4repair_space>found" ) ; } else { if ( running ) { StandardJMeterEngine . log . info ( "All<seq2seq4repair_space>thread<seq2seq4repair_space>groups<seq2seq4repair_space>have<seq2seq4repair_space>been<seq2seq4repair_space>started" ) ; } else { StandardJMeterEngine . log . info ( "Test<seq2seq4repair_space>stopped<seq2seq4repair_space>-<seq2seq4repair_space>no<seq2seq4repair_space>more<seq2seq4repair_space>thread<seq2seq4repair_space>groups<seq2seq4repair_space>will<seq2seq4repair_space>be<seq2seq4repair_space>started" ) ; } } waitThreadsStopped ( ) ; groups . clear ( ) ; if ( postIter . hasNext ( ) ) { groupCount = 0 ; JMeterContextService . clearTotalThreads ( ) ; StandardJMeterEngine . log . info ( "Starting<seq2seq4repair_space>tearDown<seq2seq4repair_space>thread<seq2seq4repair_space>groups" ) ; if ( mainGroups && ( ! ( running ) ) ) { running = ( shutdown ) & ( tearDownOnShutdown ) ; } while ( ( running ) && ( postIter . hasNext ( ) ) ) { AbstractThreadGroup group = postIter . next ( ) ; groupCount ++ ; String groupName = group . getName ( ) ; StandardJMeterEngine . log . info ( ( ( ( "Starting<seq2seq4repair_space>tearDown<seq2seq4repair_space>ThreadGroup:<seq2seq4repair_space>" + groupCount ) + "<seq2seq4repair_space>:<seq2seq4repair_space>" ) + groupName ) ) ; startThreadGroup ( group , groupCount , postSearcher , testLevelElements , notifier ) ; if ( ( serialized ) && ( postIter . hasNext ( ) ) ) { StandardJMeterEngine . log . info ( ( ( "Waiting<seq2seq4repair_space>for<seq2seq4repair_space>post<seq2seq4repair_space>thread<seq2seq4repair_space>group:<seq2seq4repair_space>" + groupName ) + "<seq2seq4repair_space>to<seq2seq4repair_space>finish<seq2seq4repair_space>before<seq2seq4repair_space>starting<seq2seq4repair_space>next<seq2seq4repair_space>post<seq2seq4repair_space>group" ) ) ; group . waitThreadsStopped ( ) ; }

Fix:
JMeterUtils . helpGC ( ) ;