-4

Can we create deadlock without thread in java? This question was asked in java interview can anybody answer this.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

2

It's not possible to run code without at least one thread. A single thread can block itself in some cases eg attempting to upgrade a read lock to a write lock.

When a thread resource starves itself, it is called a livelock

I added more detail on livelocks in Java here Is it possible for a thread to Deadlock itself?

It is also possible to create a deadlock without creating an additional thread e.g. the finalizer thread and the main thread could deadlock each other.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130