Final answer:
To simulate the CPU Scheduler in Java, create multiple threads to handle different tasks. Implement First-Come-First-Serve (FCFS), Shortest-Job-First (SJF), and Round-Robin (RR) scheduling algorithms. Update the PCBs with relevant information and consider memory limitations.
Step-by-step explanation:
To simulate the CPU Scheduler in Java, you can create multiple threads to handle different tasks. Start by reading the process information from a file using one thread and creating the Process Control Blocks (PCBs) for each job. Another thread can continuously check the available memory to load jobs from the job queue to the ready queue. The main thread will handle the scheduling algorithms based on the user's choice.
For First-Come-First-Serve (FCFS) scheduling, simply process the jobs in the order they arrived. For Shortest-Job-First (SJF) scheduling, sort the jobs based on their burst time and process the shortest job first. For Round-Robin (RR) scheduling, set a quantum of 10ms and continuously process the jobs in a circular manner.
Throughout the simulation, make sure to update the PCBs with relevant information such as turnaround time and waiting time. Additionally, consider memory limitations and ensure that jobs can only be loaded when there is enough available memory.
You need to write a Java program that simulates a CPU Scheduler, implements three scheduling algorithms, manages jobs with a PCB, and uses threads to handle file reading and queue management.
The question you asked pertains to writing a Java program that simulates a CPU Scheduler using multiple threads. This means that the program will need to implement at least two separate threads: one for reading process information from a file and creating process control blocks (PCBs), and another for managing the job queue and ready queue based on the available memory. Additionally, the main thread will be responsible for executing the scheduling algorithms: First-Come-First-Serve (FCFS), Shortest-Job-First (SJF), and Round-Robin (RR) with a quantum of 10ms. The processes will have attributes like ID, state, burst time, memory requirement, and required statistics that include turnaround and waiting times.
When implementing the FCFS scheduling algorithm, processes will be executed in the order they arrive. For the SJF algorithm, the process with the shortest burst time will be scheduled next. In the RR algorithm, each process is given a fixed time slot (quantum) and is then placed back in the ready queue if it's not finished. The provided job.txt file will contain job information formatted as specified, and the program must ensure that a process is loaded into the ready queue only if there is enough memory available to accommodate it.
The core challenge of this simulation is to manage these different threads effectively, ensuring that shared resources such as the job queue and the ready queue are handled in a thread-safe manner to avoid race conditions and ensure the correct behavior of the scheduler.
The input will be provided by the instructor, and you will have to account for the constraints provided, such as the limited main memory and the fixed number of jobs.