Scheduler still not working
This commit is contained in:
parent
4b35c32845
commit
102e80537c
@ -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=true
|
||||||
annotation.processing.enabled.in.editor=false
|
annotation.processing.enabled.in.editor=false
|
||||||
annotation.processing.processors.list=
|
annotation.processing.processors.list=
|
||||||
|
@ -86,8 +86,9 @@ public class SimpleTrader extends AbstractTrader implements EventListener{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long receive(Event task) {
|
public long receive(Event task) {
|
||||||
System.out.printf("Here we are !!! %f\n", getWorld().randNextFloat(12f, 27f));
|
// System.out.printf("Here we are !!! %f\n", getWorld().randNextFloat(12f, 27f));
|
||||||
getWorld().schedule(this, 5000);
|
System.out.printf("Here we are: %d - %d (%d)\n",Thread.currentThread().getId(),System.nanoTime()/1000,task.t );
|
||||||
|
getWorld().schedule(this, 1000);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,8 @@ package opensesim.world.scheduler;
|
|||||||
|
|
||||||
EventListener listener;
|
EventListener listener;
|
||||||
|
|
||||||
|
public long t;
|
||||||
|
|
||||||
Event(EventListener listener) {
|
Event(EventListener listener) {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,7 @@ public class Scheduler {
|
|||||||
|
|
||||||
long delay = getDelay();
|
long delay = getDelay();
|
||||||
if (delay > 0) {
|
if (delay > 0) {
|
||||||
|
System.out.printf("Worker %d sleeps for %d\n",Thread.currentThread().getId(), delay);
|
||||||
synchronized (clock) {
|
synchronized (clock) {
|
||||||
try {
|
try {
|
||||||
if (delay != -1 && !clock.isPause()) {
|
if (delay != -1 && !clock.isPause()) {
|
||||||
@ -57,9 +58,10 @@ public class Scheduler {
|
|||||||
clock.wait();
|
clock.wait();
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
System.out.printf("Interrupted\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
Event e = getNextEvent();
|
Event e = getNextEvent();
|
||||||
if (e == null) {
|
if (e == null) {
|
||||||
@ -73,7 +75,7 @@ public class Scheduler {
|
|||||||
|
|
||||||
ArrayList<Worker> workers;
|
ArrayList<Worker> workers;
|
||||||
final private Clock clock = new Clock();
|
final private Clock clock = new Clock();
|
||||||
int next = 0;
|
// int next = 0;
|
||||||
|
|
||||||
public Scheduler(int nthreads) {
|
public Scheduler(int nthreads) {
|
||||||
workers = new ArrayList<>();
|
workers = new ArrayList<>();
|
||||||
@ -83,7 +85,7 @@ public class Scheduler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Scheduler() {
|
public Scheduler() {
|
||||||
this(1);
|
this(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
@ -95,6 +97,7 @@ public class Scheduler {
|
|||||||
public Event startTimerTask(EventListener listener, long time) {
|
public Event startTimerTask(EventListener listener, long time) {
|
||||||
Event e = new Event(listener);
|
Event e = new Event(listener);
|
||||||
long t = time + clock.currentTimeMillis();
|
long t = time + clock.currentTimeMillis();
|
||||||
|
e.t=t;
|
||||||
synchronized (event_queue) {
|
synchronized (event_queue) {
|
||||||
LinkedList<Event> s = event_queue.get(t);
|
LinkedList<Event> s = event_queue.get(t);
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user