WDD_lec_24 - Multithreading 2 Lec 24 Reading Two Files...

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

View Full Document Right Arrow Icon
Multithreading 2 Lec 24
Background image of page 1

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

View Full DocumentRight Arrow Icon
Reading Two Files Simultaneously Example Code
Background image of page 2
3 Useful Thread Methods sleep (int time) Causes the currently executing thread to wait for the time (milliseconds) specified Waiting is efficient (non-busy) Threads come out of the sleep when the specified time interval expires or when interrupted by some other thread Thread coming out of sleep may go to the running or ready state depending upon the availability of the processor.
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Useful Thread Methods (cont.) sleep (int time) High priority threads should execute sleep method after some time to give low priority threads a chance to run otherwise starvation may occur Sleep can be used for delay purpose
Background image of page 4
5 Code Example: Modify Worker.java public class Worker implements Runnable { …………. public void run ( ) { for(int i=1; i<= 10; i++) { try { Thread.sleep(100); }catch (Exception ex){ System.out.println(ex); } System.out.println(job + " = " + i); } // end for } // end run }// end Worker
Background image of page 5

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

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

Page1 / 16

WDD_lec_24 - Multithreading 2 Lec 24 Reading Two Files...

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

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