Untitled
unknown
plain_text
2 years ago
777 B
6
Indexable
class MyRunnable implements Runnable {
@Override
public void run() {
try {
System.out.println("Thread started: " + Thread.currentThread().getName());
Thread.sleep(500);
System.out.println("Thread ended: " + Thread.currentThread().getName());
} catch (InterruptedException e) {
System.out.println("Thread interrupted: " + Thread.currentThread().getName());
}
}
}
public class CreateThreadExample {
public static void main(String[] args) {
MyRunnable runnable = new MyRunnable();
Thread thread1 = new Thread(runnable, "Thread 1");
Thread thread2 = new Thread(runnable, "Thread 2");
thread1.start();
thread2.start();
}
}
Editor is loading...