My issue
pls solve
My code
class ThreadFunction1 implements Runnable {
public void run() {
for (int i = 0; i < 5; i++) {
try {
Thread.sleep(10); // Sleep for 10 milliseconds
} catch (InterruptedException e) {
System.out.println(e);
}
System.out.println("Thread 1 - iteration " + i);
}
}
}
class ThreadFunction2 implements Runnable {
public void run() {
for (int i = 0; i < 5; i++) {
try {
Thread.sleep(10); // Sleep for 10 milliseconds
} catch (InterruptedException e) {
System.out.println(e);
}
System.out.println("Thread 2 - iteration " + i);
}
}
}
class Main {
public static void main(String[] args) {
Thread t1 = new Thread(new ThreadFunction1());
Thread t2 = new Thread(new ThreadFunction2());
t1.start(); // Start thread 1
t2.start(); // Start thread 2
try {
t1.join(); // Wait for thread 1 to finish
t2.join(); // Wait for thread 2 to finish
} catch (InterruptedException e) {
System.out.println(e);
}
System.out.println("Main thread: Done!");
}
}
Learning course: Advanced Java programming
Problem Link: Multithreading Programming Problem in Advanced Java programming