0% found this document useful (0 votes)
8 views1 page

Java Multithreading Example Code

The document presents a Java program that demonstrates multithreading using the Thread class. It creates a subclass of Thread, overrides the run method to print the thread ID, and starts multiple threads in the main method. The program initiates 8 threads, each executing concurrently and printing their respective IDs.

Uploaded by

himani
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Java Multithreading Example Code

The document presents a Java program that demonstrates multithreading using the Thread class. It creates a subclass of Thread, overrides the run method to print the thread ID, and starts multiple threads in the main method. The program initiates 8 threads, each executing concurrently and printing their respective IDs.

Uploaded by

himani
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

class MultithreadingDemo extends Thread {

public void run()


{

try {

[Link](
"Thread " + [Link]().getId()
+ " is running");

catch (Exception e) {

[Link]("Exception is caught");

public class Multithread {

public static void main(String[] args)

int n = 8;

for (int i = 0; i < n; i++) {

MultithreadingDemo object
= new MultithreadingDemo();

[Link]();

}
}
}

You might also like