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() {
53
53
int winningTicket = random .nextInt (totalTickets ) + 1 ;
54
54
Process selectedProcess = selectProcessByTicket (winningTicket );
55
55
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
+
56
63
selectedProcess .setWaitingTime (currentTime );
57
64
currentTime += selectedProcess .getBurstTime ();
58
65
selectedProcess .setTurnAroundTime (selectedProcess .getWaitingTime () + selectedProcess .getBurstTime ());
You can’t perform that action at this time.
0 commit comments