1. A method for optimizing code for a multi-threaded application, comprising: obtaining information associated with resource contention between executing threads, the information having been obtained while executing the code for the multi-threaded application; analyzing the resource contention information to identify regions of the code to be optimized; using a compiler to recompile the identified regions to produce optimized code; and storing the optimized code for subsequent execution.