-
Notifications
You must be signed in to change notification settings - Fork 695
Open
Description
public class SimpleConcurrency {
public static void main(String[] args) {
// Create two separate threads
Thread thread1 = new Thread(new MyRunnable("Thread 1"));
Thread thread2 = new Thread(new MyRunnable("Thread 2"));
// Start the threads
thread1.start();
thread2.start();
}
}
class MyRunnable implements Runnable {
private String name;
public MyRunnable(String name) {
this.name = name;
}
@Override
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println(name + " running iteration " + i);
try {
// Sleep for a short time to allow other thread to run
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
Metadata
Metadata
Assignees
Labels
No labels