Skip to content

Codes #281

@siddharthrgade21-a11y

Description

@siddharthrgade21-a11y

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

public class AdvancedConcurrency {
public static void main(String[] args) {
// Create a thread pool with 4 fixed threads
ExecutorService executor = Executors.newFixedThreadPool(4);

    for (int i = 0; i < 10; i++) {
        int taskId = i;
        executor.submit(() -> {
            System.out.println("Task " + taskId + " running on: " + Thread.currentThread().getName());
        });
    }

    executor.shutdown();
    try {
        if (!executor.awaitTermination(60, TimeUnit.SECONDS)) {
            executor.shutdownNow();
        }
    } catch (InterruptedException e) {
        executor.shutdownNow();
    }
}

}

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