Aula03ThreadII
class RunnableThreadDemo implements java.lang.Runnable { // RUN METHOD IS EXECUTED WHEN THREAD FIRST STARTED public void run() { System.out.println("I am an instance of the java.lang.Runnable interface "); } } public class aula03ThreadII { public static void main(String[] args) { System.out.println("Creating runnable object"); // CREATE RUNNABLE OBJECT Runnable run = new RunnableThreadDemo(); // CREATE A THREAD, AND PASS THE RUNNABLE OBJECT System.out.println("Creating first thread"); Thread t1 = new Thread(run, "Thread 1"); // CREATE A SECOND THREAD, AND PASS THE RUNNABLE OBJECT System.out.println("Creating second thread"); Thread t2 = new Thread(run, "Thread 2"); // START BOTH THREADS System.out.println("Starting both threads"); t1.start(); t2.start(); } }
Tags : PD2122, programação distribuída
0 thoughts on “Aula03ThreadII”