{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

View Full Document Right Arrow Icon
Thread Scheduling 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 ...
Image of page 1

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

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

{[ snackBarMessage ]}