Java - Programa de Colas Multinivel con Retroalimentacion

 
Vista:

Programa de Colas Multinivel con Retroalimentacion

Publicado por Esteban (1 intervención) el 01/11/2018 02:02:40
Necesito un programa de Colas Multinivel con Retroalimentacion, estuve haciendo uno pero por mas que intente no salio. Ya me enfade.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Programa de Colas Multinivel con Retroalimentacion

Publicado por Tom (1831 intervenciones) el 01/11/2018 09:55:08
¿ Qué son las "Colas Multinivel con Retroalimentacion" ?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Programa de Colas Multinivel con Retroalimentacion

Publicado por Tom (1831 intervenciones) el 01/11/2018 10:41:51
Me autorespondo, ya lo vi.
Esta tiene un comportamiento curioso:

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
public class Cola {
	/* */
	public static void main(String args[]) throws InterruptedException {
		PriorityQueue<Proceso> cola = new PriorityQueue<>();
		for(int i = 0; i < 10; i++) {
			cola.add(new Proceso(String.format("Proc %d", i), i));
		}
		for(int i = 0; i < 150; i++) {
			Proceso p = cola.poll();
			System.out.printf("Running %s\n", p.name);
			Thread.sleep(500);
			p.runs++;
			p.priority++;
			cola.add(p);
		}
	}
	/* */
	static class Proceso implements Comparable<Proceso> {
		final String name;
		private int priority;
		private int runs;
		/* */
		Proceso(String name, int prio) {
			this.name = name;
			this.priority = prio;
			this.runs = 0;
		}
		@Override
		public int compareTo(Proceso other) {
			if(other != null) {
				if(priority == other.priority) {
					return runs - other.runs;
				}
				return priority - other.priority;
			}
			return -1;
		}
	}
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar