Skip to content

Codes #181

@siddharthrgade21-a11y

Description

@siddharthrgade21-a11y

public class SimpleConcurrency {

public static void main(String[] args) {
    // Create two separate threads
    Thread thread1 = new Thread(new MyRunnable("Thread 1"));
    Thread thread2 = new Thread(new MyRunnable("Thread 2"));

    // Start the threads
    thread1.start();
    thread2.start();
}

}

class MyRunnable implements Runnable {
private String name;

public MyRunnable(String name) {
    this.name = name;
}

@Override
public void run() {
    for (int i = 0; i < 5; i++) {
        System.out.println(name + " running iteration " + i);
        try {
            // Sleep for a short time to allow other thread to run
            Thread.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions