Java thread state

I want to check the correctness of my reasoning.

First of all, I have to provide some details about the problem I'm trying to solve. A stream (part of a program) performs the following actions:

  • begins
  • it calls Thread.sleep (20ms)
  • it calls the getIn () method
  • he is trying to get a lock (lock.lock ())
  • if it successfully receives the lock, it calls Thread.sleep (100ms)
  • If the lock is not available, it calls waitCond.await ()
  • after calling Thread.sleep (100ms) it calls lock.unlock ()
  • it calls another getOut () method
  • it completes (thread.join ())

Given this, I can guess the state of the stream:

  • READY TO RUN state
  • TIMED WAITING state
  • WAITING state
  • WAITING state
  • BLOCKED state
  • WAITING state
  • WAITING state
  • TERMINATED state

thank

+5
source share
1 answer

, , READY TO RUN, RUNNABLE. , , . getIn(), , .

, , getIn() getOut(), RUNNABLE, WAITING. BLOCKED , , . , , 6. Thread.sleep(), , .

:

  • RUNNABLE
  • TIMED WAITING
  • RUNNABLE
  • BLOCKED
  • TIMED WAITING
  • BLOCKED
  • RUNNABLE
  • TERMINATED

Thread state transitions

: . , , JVM -, , .

, Profiler, . , : Java Concurrency Profiler, , VisualVM YourKit.

+8

All Articles