title: Return a method when time limit is up in - java
body: <p>i just started to learn programming (2 weeks ago), and i am trying to make a bot for a game. In the main class of the bot, there are 3 methods that needs to be returned within 2second, or it will return null. I want to avoid returning null and return what it has calculate during 2sec instead.</p>
  
  <pre><code>public ArrayList&lt;PlaceArmiesMove&gt; getPlaceArmiesMoves(BotState state, Long timeOut){
  
  ArrayList&lt;PlaceArmiesMove&gt; placeArmiesMoves = new ArrayList&lt;PlaceArmiesMove&gt;();
  
  // caculations filling the ArrayList
  
  return placeArmiesMoves;
  }
  </code></pre>
  
  <p>what i want to do is after 2 second, returning placeArmiesMoves, wether the method finished running or not. I have read about guava SimpleTimeLimiter and callWithTimeout() but i am totally lost about how to use it (i read something about multithreading but i just don't understand what this is)
  i would be incredibly grateful if someone could help me! thanks</p>