Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java parked thread

Tags:

What is the difference between a parked thread and a waiting thread in java ? I've a jboss core dump and analysing it is showing a lot of parked threads.

like image 775
Rnet Avatar asked Apr 04 '12 10:04

Rnet


People also ask

What is a parked thread Java?

Parking means suspending execution until permit is available. Permit means a permission to continue execution. A thread can suspend its execution until permit is available.

What does it mean when a thread is parked?

When you call a park method on a Thread, it disables the thread for thread scheduling purposes unless the permit is available. You can call unpark method to make available the permit for the given thread, if it was not already available.

What is blocked thread in Java?

Blocking methods in java are the particular set of methods that block the thread until its operation is complete. So, they will have to block the current thread until the condition that fulfills their task is satisfied. Since, in nature, these methods are blocking so-called blocking methods.

What is Timed_waiting in thread dump?

TIMED_WAITING. The thread is waiting for another thread to perform an action for up to a specified waiting time. TERMINATED. The thread has exited.


2 Answers

Look at Javadoc the park() method:

Disables the current thread for thread scheduling purposes unless the permit is available. If the permit is available then it is consumed and the call returns immediately; otherwise the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happens:

Some other thread invokes unpark with the current thread as the target; or Some other thread interrupts the current thread; or The call spuriously (that is, for no reason) returns. This method does not report which of these caused the method to return. Callers should re-check the conditions which caused the thread to park in the first place. Callers may also determine, for example, the interrupt status of the thread upon return.

So a parked thread is a thread blocked using LockSupport.park().

like image 80
dash1e Avatar answered Sep 22 '22 18:09

dash1e


Both park() and wait() will result in a disabled thread. Making a disabled thread active again depends on how it was disabled.

A thread that has been disabled by calling LockSupport.park() will remain disabled until:

  • some other thread calls unpark(), or
  • some other thread calls interrupt(), or
  • "the call spuriously (that is, for no reason) returns"

A thread that has been disabled by calling Object's wait() – which is equivalent to calling wait(0) – will remain disabled until:

  • some other thread calls notify() or notifyAll(), or
  • some other thread calls interrupt() on the disabled thread
like image 29
kaan Avatar answered Sep 20 '22 18:09

kaan