Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Creating a simulation of an operating system scheduler handling multiple threads

ID: 656296 • Letter: C

Question

Creating a simulation of an operating system scheduler handling multiple threads or processes. The student will create a program that launches 6 - 10 worker threads simulating a processor bound, I/O bound and an intermediate of the two types. The program will schedule the tasks using the First-Come, First-Served (FCFS), Shortest Job First, and Round Robin scheduling algorithms. The Program should be written in Java and the Round Robin algorithm should employ the suspend() and resume() thread methods (yes I know the methods are depreciated).

Explanation / Answer

import java.util.ArrayList; import java.util.List; public class ThreadScheduler { private List threadList = new ArrayList(); public ThreadScheduler(){ for (int i = 0 ; i < 100 ; i++){ threadList.add(new RoundRobinProcess()); new Thread(threadList.get(i)).start(); } } private class RoundRobinProcess implements Runnable{ private final Object lock = new Object(); private volatile boolean suspend = false , stopped = false; @Override public void run() { while(!stopped){ while (!suspend){ // do work } synchronized (lock){ try { lock.wait(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return; } } } } public void suspend(){ suspend = true; } public void stop(){ suspend = true;stopped = true; synchronized (lock){ lock.notifyAll(); } } public void resume(){ suspend = false; synchronized (lock){ lock.notifyAll(); } } } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote