-4

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

Mark Rotteveel
  • 90,369
  • 161
  • 124
  • 175

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
  • 513,304
  • 74
  • 731
  • 1,106