Commit 834a5e5d by Pedro J Sanchez

Upload New File

parent 65750377
package es.uja.cursojee.simulaeventos;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import es.uja.cursojee.simulaeventos.Constantes.TipoEvento;
public class TareaGestor2 implements Callable<List<Evento>> {
private final String name;
private final int numEventos;
public TareaGestor2(String name, int numEventos) {
super();
this.name = name;
this.numEventos = numEventos;
}
@Override
public List<Evento> call() throws Exception {
ArrayList<Evento> listaEventos = new ArrayList();
System.out.println("Hilo(" + name + ") ha iniciado su ejecución");
try {
for(int i = 0; i < numEventos; i++)
crearEvento(i+1, listaEventos);
System.out.println("Hilo(" + name + ") ha finalizado su ejecución");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.println("Hilo(" + name + ") se CANCELA su ejecución");
}
return listaEventos;
}
private void crearEvento(int i, List<Evento> listaEventos) throws InterruptedException {
if( Thread.currentThread().interrupted() )
throw new InterruptedException();
Evento evento = new Evento("id-"+i, TipoEvento.getEvento(), "Localizacion", new Date(), "Descripcion",
Constantes.aleatorio.nextInt(Constantes.D100)+1);
System.out.println("Hilo(" + name + ") ha creado el evento número " + i + " de un total de " + numEventos);
TimeUnit.SECONDS.sleep(Constantes.TIEMPO_SIMULADO);
listaEventos.add(evento);
}
public String getName() {
return name;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment