title: How to implement synchronous method timeouts in Java?
body: <p>I have an synchronous execution path which needs to either complete or timeout within a given time frame. Let's say I have a class with main() method in which I invoke methods A() which in-turn calls B() and that in-turn calls C() of same or different classes.....all synchronous without using an external resource like database , webservice or file system (where each of them could be timed out independently using a TxManager or respective timeout api's). So it's more like a CPU or memory intensive computation. How do I code for it's timeout in Java ?</p>
  
  <p>I have looked at TimerTask but that more of making the flow async and for scheduling tasks. Any other suggestions ?</p>