Java Thread Model - The Java Threading API 1 Simple Applet...

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

View Full Document Right Arrow Icon
1 The Java Threading API
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 Simple Applet Example public class OurClass { public void run() { for( int I=0; I<100; I++) { System.out.println(“Hello”); } } } OurClass is a class OurClass has a single method: run() The run() method writes a string 100 times to the Java console or standard output We instantiate an OurClass object and call its run method: the “Hello” message is printed 100 times. The caller of the run method waits until it finishes before it continues import java.applet.Applet public class OurApplet extend Applet { public void init() { OurClass oc = new OurClass(); oc.run(); } }
Background image of page 2
3 Threading the Simple Applet We want the run() method of OurClass to execute in parallel with the init() method and other methods of the applet We must modify the OurClass class so that it can be executed by a new thread We do this by making OurClass inherit from the Thread class (java.lang.Thread)
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 Threading the Simple Applet, contd. public class OurClass
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/14/2011 for the course COP 4610L taught by Professor Staff during the Spring '09 term at University of Central Florida.

Page1 / 10

Java Thread Model - The Java Threading API 1 Simple Applet...

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

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