📘 Lesson  ·  Lesson 35

Multithreading

Multithreading

What is Multithreading?

Multithreading lets a program run multiple tasks at the same time using threads — improving speed and responsiveness.

Creating a Thread

class MyThread extends Thread {
    public void run() {
        System.out.println("Thread running");
    }
}
MyThread t = new MyThread();
t.start();   // starts a new thread

// Or with Runnable
Runnable task = () -> System.out.println("Task running");
new Thread(task).start();

Thread Lifecycle

New → Runnable → Running → (Waiting/Blocked) → Terminated. start() moves it to Runnable; the scheduler runs it.

Summary

  • Multithreading runs tasks concurrently via Thread or Runnable.
  • Call start() (not run()) to begin a new thread.

Multithreading क्या है?

Multithreading program को threads से कई tasks एक साथ चलाने देता है — speed और responsiveness बढ़ाता है।

Thread बनाना

class MyThread extends Thread {
    public void run() {
        System.out.println("Thread running");
    }
}
MyThread t = new MyThread();
t.start();   // नया thread शुरू करता है

// या Runnable से
Runnable task = () -> System.out.println("Task running");
new Thread(task).start();

Thread Lifecycle

New → Runnable → Running → (Waiting/Blocked) → Terminated। start() इसे Runnable करता है; scheduler चलाता है।

सारांश

  • Multithreading Thread या Runnable से tasks एक साथ चलाता है।
  • नया thread शुरू करने को start() call करें (run() नहीं)।
← Back to Java Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

\n