File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed
src/main/java/com/thealgorithms/scheduling Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,13 @@ public List<Process> scheduleProcesses() {
5353 int winningTicket = random .nextInt (totalTickets ) + 1 ;
5454 Process selectedProcess = selectProcessByTicket (winningTicket );
5555
56+ if (selectedProcess == null ) {
57+ // This should not happen in normal circumstances, but we'll handle it just in case
58+ System .err .println ("Error: No process selected. Recalculating total tickets." );
59+ totalTickets = processes .stream ().mapToInt (Process ::getTickets ).sum ();
60+ continue ;
61+ }
62+
5663 selectedProcess .setWaitingTime (currentTime );
5764 currentTime += selectedProcess .getBurstTime ();
5865 selectedProcess .setTurnAroundTime (selectedProcess .getWaitingTime () + selectedProcess .getBurstTime ());
You can’t perform that action at this time.
0 commit comments