WDD_lec_23 - Multithreading Lec 23 Threads The ability to...

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

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

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

View Full DocumentRight Arrow Icon
2 Threads The ability to do multiple things at once within the same application Finer granularity of concurrency Lightweight Easy to create and destroy Shared address space Can share memory variables directly May require more complex synchronization logic because of shared address space
Background image of page 2
Three Loops Sequential Execution
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 Example Code: ThreeLoopTest public class ThreeLoopTest { public static void main (String args[ ]){ // first loop for (int i=1; i<= 5; i++) System.out.println(“first ” +i); // second loop for (int j=1; j<= 5; j++) System.out.println(“second ” + j); // third loop for (int k=1; k<= 5; k++) System.out.println(“third ” + k); } }
Background image of page 4
5 Compile & Execute: ThreeLoopTest
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Multi-Threaded Output
Background image of page 6
7 Creating Threads in Java Two approaches Using Interface Implement the runnable interface in a class Provide an implementation for the run() method Instantiate Thread object by passing runnable object in constructor
Background image of page 7

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

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

Page1 / 18

WDD_lec_23 - Multithreading Lec 23 Threads The ability to...

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

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