Multithreading in Java
Multithreading allows you to perform multiple tasks simultaneously within the same program. This can improve the performance of your program and make it more responsive to user input.
Example code:
java
public class MyThread extends Thread {
public void run() {
for (int i = 0; i < 10; i++) {
System.out.println("Thread " + Thread.currentThread().getId() + " is running.");
}
}
}
MyThread thread1 = new MyThread();
MyThread thread2 = new MyThread();
thread1.start();
thread2.start();
No comments:
Post a Comment