{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

081029slides_handouts

081029slides_handouts - Priorities Landed on Mars July 4...

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

View Full Document Right Arrow Icon
1 UVa CS205 Engineering Software 2008 Priorities Landed on Mars, July 4, 1997 Sojourner Rover UVa CS205 Engineering Software 2008 Counter c = new Counter (); IncThread ithread = new IncThread (c); DecThread dthread = new DecThread (c); ithread.setPriority (Thread.NORM_PRIORITY); ithread.start (); dthread.setPriority (Thread.MAX_PRIORITY); dthread.start (); Running inc thread: Thread[Thread-0,5,main] / Value: 1 Running dec thread: Thread[Thread-1,10,main] / Value: 0 Running inc thread: Thread[Thread-0,5,main] / Value: 1 Running dec thread: Thread[Thread-1,10,main] / Value: 0 Running inc thread: Thread[Thread-0,5,main] / Value: 1 Running dec thread: Thread[Thread-1,10,main] / Value: 0 Running inc thread: Thread[Thread-0,5,main] / Value: 1 Running dec thread: Thread[Thread-1,10,main] / Value: 0 UVa CS205 Engineering Software 2008 Priorities In general, threads with higher priorities will be scheduled preferentially. There are no guarantees: up to Java scheduler Thread class: void setPriority (int newPriority) // MODIFIES: this // EFFECTS: Changes the priority of this // thread to newPriority . UVa CS205 Engineering Software 2008 Priorities, Priorities ithread.setPriority (Thread.NORM_PRIORITY); ithread.start (); dthread.setPriority (Thread.MIN_PRIORITY); dthread.start (); The ithread should run more than the dthread, but there is no guarantee. Thread.MIN_PRIORITY Thread.NORM_PRIORITY Thread.MAX_PRIORITY
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