Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Start with multithreadings

This Java code demonstrates a simple multithreading experiment using the Thread class. The experiment class extends Thread and overrides its run method to print a message indicating that the thread is running. In the Multithread class, ten instances of the experiment class are created and started sequentially with a delay of 1000 milliseconds between each start.

Usage

To run the experiment:

  1. Compile the Java files.
  2. Run the Multithread class.

Code

class experiment extends Thread {
    public void run() {
        try {
            System.out.println("Thread " + Thread.currentThread().threadId() + " is running");
        } catch (Exception e) {
            System.out.println("Exception is caught");
        }
    }
}

public class Multithread {
    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 10; i++) {
            experiment object = new experiment();
            object.start();
            Thread.sleep(1000);
        }
    }
}

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages