title: Can I use variables across all the threads in the thread groups in jmeter?
body: <p>I'm trying to create a test plan for rate-limiting behavior.
  I set a rule that blocks after X requests per minute, and I want to check that I get response code 200 until I reached the X requests, and from then, to get 429. I created a counter that shared between all the threads, but it seems to be a mess because it's not a thread-safe.</p>
  <p>This is my beanshell &quot;once only controller&quot;:</p>
  <pre><code>String props_pre_fix = ${section_id} + &quot;-&quot; + ${START.HMS};
  props.remove(&quot;props_pre_fix&quot; + ${section_id}, props_pre_fix);
  props.put(&quot;props_pre_fix&quot; + ${section_id}, props_pre_fix);
  
  props.put(props_pre_fix + &quot;_last_response_code&quot;, &quot;200&quot;);
  props.put(props_pre_fix + &quot;_my_counter&quot;, &quot;0&quot;);
  </code></pre>
  <p>and this is the beanshell assertion:</p>
  <pre><code>String props_pre_fix = props.get(&quot;props_pre_fix&quot; + ${section_id});
  //log.info(&quot;props_pre_fix &quot; + props_pre_fix);
  
  //extract my counter from props
  int my_counter = Integer.parseInt(props.get(props_pre_fix + &quot;_my_counter&quot;));
  
  //extract last response code
  String last_response_code = props.get(props_pre_fix + &quot;_last_response_code&quot;);
  log.info(&quot;last_response_code &quot; + last_response_code);
  
  //if last seconds is greater than current seconds it means we are in a new minute - set counter to zero
  if(last_response_code.equals(&quot;429&quot;) &amp;&amp; ResponseCode.equals(&quot;200&quot;)){
      log.info(&quot;we moved to a new minute - my_counter should be zero&quot;);
      my_counter = 0;
  }
  
  //increase counter
  my_counter++;
  log.info(&quot;set counter with value: &quot; + my_counter);
  //save counter
  props.put(props_pre_fix + &quot;_my_counter&quot;, my_counter + &quot;&quot;);
  log.info(&quot;counter has set with value: &quot; + my_counter);
  
  if (ResponseCode.equals(&quot;200&quot;)) {
      props.put(props_pre_fix + &quot;_last_response_code&quot;, &quot;200&quot;);
      if(my_counter &lt;= ${current_limit}){
          Failure = false;
      } 
      else {
          Failure = true;
          FailureMessage = &quot;leakage of &quot; + (my_counter - ${current_limit}) + &quot; requests&quot;;
      }
  } 
  else if (ResponseCode.equals(&quot;429&quot;)) {
      props.put(props_pre_fix + &quot;_last_response_code&quot;, &quot;429&quot;);
       if(my_counter &gt; ${current_limit}){
              Failure = false;
      } 
  }
  </code></pre>
  <p>I'm using props to share the counter, but I obviously feel that this is not the right way to do it.
  Can you suggest me how to do that?</p>