-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScheduler.java
More file actions
48 lines (42 loc) · 1.37 KB
/
Scheduler.java
File metadata and controls
48 lines (42 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package BloodMatch.src.bloodmatch;
import java.util.ArrayList;
// a class, which manages the thread flow.
public class Scheduler {
static ArrayList<PatientThread> queue = new ArrayList<>();
static int max = 0;
// method, which manipulates with a thread, based on priority.
synchronized static void manageFLow() {
startThreads();
maxPriority();
for (PatientThread thread : queue) {
if (thread.thrd.getPriority() == max) {
max = 0;
thread.requestResume();
Patient.removePatient(thread.patient);
}
}
}
// method, which resumes the next suspended thread.
static void triggerNext() {
for (PatientThread thread : queue) {
if (thread.suspended) {
thread.requestResume();
return;
}
}
}
// method, which finds the highest priority on queue array.
static void maxPriority() {
for (PatientThread thread : queue) {
if (thread.thrd.getPriority() > max)
max = thread.thrd.getPriority();
}
}
// method, which starts all threads.
static void startThreads() {
for (PatientThread thread : queue) {
thread.thrd.start();
thread.requestSuspend();
}
}
}