title: Java byecode maniulation to detect potential deadlocks
body: <p>I've been caught by yet another deadlock in our Java application and started thinking about how to detect potential deadlocks in the future. I had an idea of how to do this, but it seems almost too simple.</p>
  
  <p>I'd like to hear people's views on it.</p>
  
  <p>I plan to run our application for several hours in our test environment, using a typical data set.</p>
  
  <p>I think it would be possible to perform bytecode manipulation on our application such that, whenever it takes a lock (e.g. entering a synchronized block), details of the lock are added to a ThreadLocal list.</p>
  
  <p>I could write an algorithm that, at some later point, compares the lists for all threads and checks if any contain the same pair of locks in opposite order - this would be reported as a deadlock possibility. Again, I would use bytecode manipulation to add this periodic check to my application.</p>
  
  <p>So my question is this: is this idea (a) original and (b) viable? </p>