This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
There's no universal way to avoid deadlock for any given program. The way to prevent it is to design your application correctly. You'd be better off reading the large number of papers on the subject that you can find through any search engine. As this is a very complex subject, any answer here is going to be cursory at best.