Scheduler still not working

This commit is contained in:
7u83 2018-12-20 10:51:16 +01:00
parent 4b35c32845
commit 102e80537c
4 changed files with 12 additions and 6 deletions

View File

@ -1,4 +1,4 @@
#Thu, 20 Dec 2018 09:42:18 +0100
#Thu, 20 Dec 2018 10:46:44 +0100
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processors.list=

View File

@ -86,8 +86,9 @@ public class SimpleTrader extends AbstractTrader implements EventListener{
@Override
public long receive(Event task) {
System.out.printf("Here we are !!! %f\n", getWorld().randNextFloat(12f, 27f));
getWorld().schedule(this, 5000);
// System.out.printf("Here we are !!! %f\n", getWorld().randNextFloat(12f, 27f));
System.out.printf("Here we are: %d - %d (%d)\n",Thread.currentThread().getId(),System.nanoTime()/1000,task.t );
getWorld().schedule(this, 1000);
return -1;
}

View File

@ -34,6 +34,8 @@ package opensesim.world.scheduler;
EventListener listener;
public long t;
Event(EventListener listener) {
this.listener = listener;
}

View File

@ -49,6 +49,7 @@ public class Scheduler {
long delay = getDelay();
if (delay > 0) {
System.out.printf("Worker %d sleeps for %d\n",Thread.currentThread().getId(), delay);
synchronized (clock) {
try {
if (delay != -1 && !clock.isPause()) {
@ -57,9 +58,10 @@ public class Scheduler {
clock.wait();
}
} catch (InterruptedException e) {
System.out.printf("Interrupted\n");
}
}
continue;
}
Event e = getNextEvent();
if (e == null) {
@ -73,7 +75,7 @@ public class Scheduler {
ArrayList<Worker> workers;
final private Clock clock = new Clock();
int next = 0;
// int next = 0;
public Scheduler(int nthreads) {
workers = new ArrayList<>();
@ -83,7 +85,7 @@ public class Scheduler {
}
public Scheduler() {
this(1);
this(10);
}
public void start() {
@ -95,6 +97,7 @@ public class Scheduler {
public Event startTimerTask(EventListener listener, long time) {
Event e = new Event(listener);
long t = time + clock.currentTimeMillis();
e.t=t;
synchronized (event_queue) {
LinkedList<Event> s = event_queue.get(t);
if (s == null) {