Tuesday, May 6, 2008

Deadlock with a single thread in Java

The classical definition of a deadlock involves two threads at the least. The other day I was joking with my colleague that it takes talent to deadlock with a single thread. It got me thinking if it is even possible. Then I realized the following code will deadlock with just a single thread.

Thread.currentThread().join();

Like I said, it takes talent ;)

1 comment:

  1. If you want the thread to run to alive for ever and to be dead only after i kill the java application explicitly. We can say that as well known and required dead lock or need for a thread to be alive for ever.

    ReplyDelete