Cycle 03
Lab Cycle 3 — Advanced Java
Multithreading
Problem Statement
Write a Java program to create threads by extending Thread class.
class MyThread extends Thread {
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println(Thread.currentThread().getId() + ": " + i);
}
}
}
public class ThreadDemo {
public static void main(String[] args) {
MyThread t1 = new MyThread();
MyThread t2 = new MyThread();
t1.start();
t2.start();
}
}
Question 4 of 5