Does not go into endless loop if trader returns 0
This commit is contained in:
parent
c877d42e41
commit
5a9b8240cc
@ -42,18 +42,18 @@ import java.util.TreeSet;
|
|||||||
*/
|
*/
|
||||||
public class Scheduler extends Thread {
|
public class Scheduler extends Thread {
|
||||||
|
|
||||||
private double multiplier = 0.0;
|
private double acceleration = 0.0;
|
||||||
|
|
||||||
public void setMultiply(double val) {
|
public void setAcceleration(double val) {
|
||||||
|
|
||||||
this.multiplier = val;
|
this.acceleration = val;
|
||||||
synchronized(this){
|
synchronized (this) {
|
||||||
this.notify();
|
this.notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getMultiply() {
|
public double getAcceleration() {
|
||||||
return this.multiplier;
|
return this.acceleration;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final SortedMap<Long, SortedSet<TimerTask>> event_queue = new TreeMap<>();
|
private final SortedMap<Long, SortedSet<TimerTask>> event_queue = new TreeMap<>();
|
||||||
@ -61,6 +61,7 @@ public class Scheduler extends Thread {
|
|||||||
public interface TimerTask {
|
public interface TimerTask {
|
||||||
|
|
||||||
long timerTask();
|
long timerTask();
|
||||||
|
|
||||||
long getID();
|
long getID();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +86,6 @@ public class Scheduler extends Thread {
|
|||||||
this.initScheduler();
|
this.initScheduler();
|
||||||
super.start();
|
super.start();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ObjectComparator implements Comparator<Object> {
|
private class ObjectComparator implements Comparator<Object> {
|
||||||
@ -93,7 +93,7 @@ public class Scheduler extends Thread {
|
|||||||
@Override
|
@Override
|
||||||
public int compare(Object o1, Object o2) {
|
public int compare(Object o1, Object o2) {
|
||||||
|
|
||||||
return (((TimerTask)o1).getID() - ((TimerTask)o2).getID())<0 ? -1:1;
|
return (((TimerTask) o1).getID() - ((TimerTask) o2).getID()) < 0 ? -1 : 1;
|
||||||
//return System.identityHashCode(o1) - System.identityHashCode(o2);
|
//return System.identityHashCode(o1) - System.identityHashCode(o2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,9 +108,10 @@ public class Scheduler extends Thread {
|
|||||||
public long currentTimeMillis1() {
|
public long currentTimeMillis1() {
|
||||||
|
|
||||||
long diff = System.currentTimeMillis() - last_time_millis;
|
long diff = System.currentTimeMillis() - last_time_millis;
|
||||||
// diff=12199999L;
|
|
||||||
|
// diff = 12199999L;
|
||||||
last_time_millis += diff;
|
last_time_millis += diff;
|
||||||
this.current_time_millis += diff * this.multiplier;
|
this.current_time_millis += diff * this.acceleration;
|
||||||
//System.out.printf("Current TM: %f\n", this.current_time_millis);
|
//System.out.printf("Current TM: %f\n", this.current_time_millis);
|
||||||
return (long) this.current_time_millis;
|
return (long) this.current_time_millis;
|
||||||
|
|
||||||
@ -181,15 +182,16 @@ public class Scheduler extends Thread {
|
|||||||
long t = event_queue.firstKey();
|
long t = event_queue.firstKey();
|
||||||
long ct = currentTimeMillis1();
|
long ct = currentTimeMillis1();
|
||||||
|
|
||||||
//System.out.printf("Current CMP %d %d\n", ct, t);
|
|
||||||
if (t <= ct) {
|
if (t <= ct) {
|
||||||
this.current_time_millis = t;
|
this.current_time_millis = t;
|
||||||
SortedSet s = event_queue.get(t);
|
SortedSet s = event_queue.get(t);
|
||||||
event_queue.remove(t);
|
Object rc = event_queue.remove(t);
|
||||||
Iterator<TimerTask> it = s.iterator();
|
Iterator<TimerTask> it = s.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
TimerTask e = it.next();
|
TimerTask e = it.next();
|
||||||
long next_t = this.fireEvent(e);
|
long next_t = this.fireEvent(e);
|
||||||
|
if (next_t == 0 )
|
||||||
|
next_t++;
|
||||||
|
|
||||||
this.addEvent(e, next_t + t);
|
this.addEvent(e, next_t + t);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user