Describe the lifecycle of a thread in Java and how you would prevent deadlock in a multithreading environment.