Content-Length: 3136104 | pFad | http://www.scribd.com/doc/7217752/#
th: 2988259Java Threads - Tutorial
Java Threads - Tutorial
Java Threads - Tutorial
RUNNABLE RUNNABLE
BLOCKED/ start() BLOCKED/
NEW not WAITING/ NEW not WAITING/
running running TIMED_WAITING running running TIMED_WAITING
TERMINATED TERMINATED
Thread Lifecycle: 4 states Thread Lifecycle: 4 states
sleep() sleep()
block on I/O block on I/O
wait() wait()
RUNNABLE RUNNABLE
start() BLOCKED/ start() BLOCKED/
NEW not WAITING/ NEW not WAITING/
running running TIMED_WAITING running running TIMED_WAITING
time elapsed
I/O done
notify()
TERMINATED TERMINATED
TERMINATED
O/S JVM
Beyond Green Threads Java Threads / Kernel Threads
! Green threads have all the disadvantage of ! In modern JVMs, application threads are
user-level threads (see previous set of lecture mapped to kernel threads
notes)
application
" Most importantly: Cannot exploit multi-core, multi- scheduler
threads
RUNNABLE
not
running running
! The Thread class has a setPriority() and a ! Whenever there is a choice between multiple runnable
threads, the JVM picks the higher priority one
getPriority() method " High priority threads may yield to prevent starvation of low-
priority threads
" A new Thread inherits the priority of the thread
that created it ! The JVM is preemptive
" If a higher priority thread is started, it gets to run
! Thread priorities are integers ranging ! Modern JVMs (post green threads) use time slicing
between Thread.MIN_PRIORITY and " Threads of the highest priorities get chosen in a round-robin
fashion
Thread.MAX_PRIORITY " The use of yield() isn’t required but, as we saw, it can increase
" The higher the integer, the higher the priority the frequency of switching between threads
! In spite of all this:
" The JVM can only influence the way in which threads are
scheduled
" Ultimately, the decision is left to the O/S
Fetched URL: http://www.scribd.com/doc/7217752/#
Alternative Proxies: