Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Java Thread Priorities: Thread Scheduling and Context Switching, Lecture notes of Java Programming

Java thread priorities, which determine how threads are treated in relation to each other. Thread priorities are integers that specify the relative importance of one thread over another. The rules for context switching include voluntary relinquishment and preemption by a higher-priority thread. Threads can voluntarily yield control by sleeping or blocking on I/O, while preemption occurs when a higher-priority thread demands the CPU.

Typology: Lecture notes

2019/2020

Uploaded on 04/08/2020

deepasree-varma-1
deepasree-varma-1 🇮🇳

1 document

1 / 16

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Java Thread
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Java Thread Priorities: Thread Scheduling and Context Switching and more Lecture notes Java Programming in PDF only on Docsity!

Java Thread

Thread Priorities

  • (^) Java assigns to each thread a priority that determines how that thread should be treated with respect to the others.
  • (^) Thread priorities are integers that specify the relative priority of one thread to another.
  • (^) A thread’s priority is used to decide when to switch from one running thread to the next.
  • (^) This is called a context switch.

Thread Priorities

  1. A thread can voluntarily relinquish control.
    • (^) This is done by explicitly yielding,
    • (^) sleeping, or
    • (^) blocking on pending I/O.
    • (^) In this scenario, all other threads are examined, and the highest-priority thread that is ready to run is given the CPU.

Thread Priorities

  1. A thread can be preempted by a higher-priority thread.
    • (^) In this case, a lower-priority thread that does not yield the processor is simply preempted—no matter what it is doing— by a higher-priority thread.
    • (^) Basically, as soon as a higher-priority thread wants to run, it does.
    • (^) This is called preemptive multitasking

Thread Priorities

  • (^) To set a thread’s priority, use the setPriority( ) method, which is a member of Thread.
  • (^) This is its general form: final void setPriority(int level)
  • (^) Here, level specifies the new priority setting for the calling thread.
  • (^) The value of level must be within the range MIN_PRIORITY and MAX_PRIORITY.
  • (^) Currently, these values are 1 and 10 , respectively.
  • (^) To return a thread to default priority, specify NORM_PRIORITY , which is currently 5.
  • (^) These priorities are defined as static final variables within Thread.