-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcesador.java
More file actions
59 lines (52 loc) · 1.67 KB
/
Procesador.java
File metadata and controls
59 lines (52 loc) · 1.67 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
49
50
51
52
53
54
55
56
57
58
59
public class Procesador {
private boolean disponible;
int quantum;
int tiempoEjecucionT;
int tiempoEjecucionP;
int contadorFaltante;
public Procesador() {
disponible = true;
quantum = 4;
tiempoEjecucionT=0;
tiempoEjecucionP=0;
contadorFaltante=0;
}
public boolean estaDispoble() {
return disponible == true;
}
public void setDisponible(boolean disponible) {
this.disponible = disponible;
}
public void ejecutar(Proceso proceso) {
this.quantum = 4;
for(int i = 0; i < this.quantum; i++) {
if(proceso.getTiempoRequeridoEjecucion() == 0){
this.quantum = i;
proceso.tiempoQuantumAntes = tiempoEjecucionT;
proceso.tiempoQuantumTotal = tiempoEjecucionT+i;
return;
}
System.out.printf("%s en ejecucion %d msg\n", proceso.getNombre(), proceso.getTiempoRequeridoEjecucion());
dormirProcesador(1000);
int aux = proceso.getTiempoRequeridoEjecucion();
proceso.setTiempoRequeridoEjecucion(--aux);
}
this.quantum =4;
//proceso.tiempoQuantumF=tiempoEjecucionP;
//Codigo para obtener el tiempo de ejecucion antes
if (proceso.getTiempoRequeridoEjecucion() == 0){
proceso.tiempoQuantumSuma += contadorFaltante;
}else{
proceso.tiempoQuantumSuma += this.quantum;
}
//Codigo para obtener el tiempo de ejecucion anterior
proceso.tiempoQuantumAntes = tiempoEjecucionT;
//Codigo para obetenr el tiempo de ejecucion total
proceso.tiempoQuantumTotal = tiempoEjecucionT+this.quantum;
}
private void dormirProcesador(int tempo) {
try{
Thread.sleep(tempo);
} catch (InterruptedException e){}
}
}