title: How to stop running method execution after a certain time period?
body: <p>In a class, I have a main method and temp method and I'm calling the temp method from main method but after 20 seconds I want to stop these method execution and start again to call temp method.</p>
  
  <p>I have tried to use thread in the code but it won't work.</p>
  
  <pre><code>public static void main(){
    temp();   
   }
  
   public void temp(){
      // here is my code which takes some time more than 20 second to 
      // so i want to stop these method execution and call again temp method
   }
  </code></pre>