Programming Languages Java Subjective
Sep 24, 2025

Implement a custom thread pool executor.

Detailed Explanation
public class CustomThreadPool {\n private final BlockingQueue taskQueue;\n private final List workers;\n private volatile boolean isShutdown;\n \n public CustomThreadPool(int poolSize) {\n taskQueue = new LinkedBlockingQueue<>();\n workers = new ArrayList<>();\n for (int i = 0; i < poolSize; i++) {\n Worker worker = new Worker();\n workers.add(worker);\n worker.start();\n }\n }\n \n public void execute(Runnable task) {\n if (!isShutdown) {\n taskQueue.offer(task);\n }\n }\n \n private class Worker extends Thread {\n public void run() {\n while (!isShutdown) {\n try {\n Runnable task = taskQueue.take();\n task.run();\n } catch (InterruptedException e) {\n Thread.currentThread().interrupt();\n }\n }\n }\n }\n}
Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback