Lecture 20b - Thread Scheduling Multiple threads compete...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Multiple threads compete for processor time Threads are scheduled by the OS o The scheduler decides which thread runs, and for how long o A thread can be pre-empted or resumed at any time You can influence the scheduler by adjusting a thread’s priority o High priority threads get more CPU time than low priority threads setPriority(int newPriority) o new Priority is an int from 1 (low) to 10(high) o Can use the class constants: MAX_PRIORITY (1) MAX_PRIORITY (10) NORM_PRIORITY (5) o A new thread inherits the priority of the thread that created it Can only be changed after creating the thread o Use getPriority() to find a thread’s current priority o A thread can use yield() inside its run() method to hint to the scheduler to choose another thread to run Coordinating Threads Use join() to cause a thread to wait for another thread to finish Eg: MyThread t1 = new MyThread(); t1.start(); // 2 threads now running, main and t1 ... // Pause main thread until t1 is finished
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/04/2010 for the course CPSC 233 taught by Professor Li during the Fall '09 term at University of Calgary.

Page1 / 4

Lecture 20b - Thread Scheduling Multiple threads compete...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online