Skip to content

Codes #285

@siddharthrgade21-a11y

Description

@siddharthrgade21-a11y

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPoolExample {
public static void main(String[] args) {
// Creates a pool of 3 worker threads
ExecutorService executor = Executors.newFixedThreadPool(3);

    for (int i = 1; i <= 5; i++) {
        int taskNumber = i;
        executor.submit(() -> {
            System.out.println("Processing task " + taskNumber + " on " + Thread.currentThread().getName());
            try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); }
        });
    }

    executor.shutdown(); // Stops accepting new tasks
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions