title: Algorithm to resolve general dependencies
body: <p>Imagine if you have a bunch of methods (Java in this case) that depends on each other.</p>
  
  <ul>
  <li>methodY depends on methodA, methodB, methodC
  <li>methodX depends on methodA, methodB
  <li>methodB depends on methodA, methodF
  <li>methodT doesnt depends on anything
  <li>methodU depends on methodW
  <li>and so on
  </ul>
  
  <p>If methodA depends on methodB that means methodB has to be executed first before methodA is executed.<br/></p>
  
  <p>Assume you do not need to worry about cyclic dependencies.<br/></p>
  
  <p>Each method is run by a Thread, there is a fixed size thread pool.<br/></p>
  
  <p>If there are no cyclic dependencies, is it possible for all of them to run eventually ?<br/>
  How do I queue the threads so all of them would run eventually ?<br/></p>
  
  <p>For example this wouldn't work<br/>
  methodA depends on methodB, methodC depends on methodB, thread pool size is 2. If I queue methodA and methodC, they would hang around indefinitely because both are waiting for methodB but pool is already full.</p>