Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Pedro J Sanchez
/
simulaeventos
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
834a5e5d
authored
Mar 27, 2020
by
Pedro J Sanchez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Upload New File
parent
65750377
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
0 deletions
src/main/java/es/uja/cursojee/simulaeventos/TareaGestor2.java
src/main/java/es/uja/cursojee/simulaeventos/TareaGestor2.java
0 → 100644
View file @
834a5e5d
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
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment