Deadlocks occur when threads mutually block each other by holding resources the other needs. An example program demonstrates deadlock by having two threads call synchronized methods on separate objects that each pause briefly before calling a method on the other object. To avoid deadlock, resources should be requested in the same order by all threads or code within synchronized blocks should not halt thread execution.