Better schedulet
This commit is contained in:
parent
3039cee680
commit
2800dd7145
@ -55,7 +55,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
|
|||||||
// int item_width = 10;
|
// int item_width = 10;
|
||||||
//int items = 350;
|
//int items = 350;
|
||||||
//long ntime = 0;
|
//long ntime = 0;
|
||||||
OHLCData data = new OHLCData(60000*15);
|
OHLCData data = new OHLCData(60000*30);
|
||||||
|
|
||||||
OHLCDataItem current = null;
|
OHLCDataItem current = null;
|
||||||
|
|
||||||
|
@ -335,7 +335,7 @@
|
|||||||
<Component class="javax.swing.JSpinner" name="jSpinner2">
|
<Component class="javax.swing.JSpinner" name="jSpinner2">
|
||||||
<Properties>
|
<Properties>
|
||||||
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
|
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
|
||||||
<SpinnerModel initial="0.0" maximum="1000.0" minimum="0.0" numberType="java.lang.Double" stepSize="0.1" type="number"/>
|
<SpinnerModel initial="0.0" maximum="10000.0" minimum="0.0" numberType="java.lang.Double" stepSize="0.1" type="number"/>
|
||||||
</Property>
|
</Property>
|
||||||
</Properties>
|
</Properties>
|
||||||
<Events>
|
<Events>
|
||||||
|
@ -219,7 +219,7 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
jSpinner2.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, 1000.0d, 0.1d));
|
jSpinner2.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, 10000.0d, 0.1d));
|
||||||
jSpinner2.addChangeListener(new javax.swing.event.ChangeListener() {
|
jSpinner2.addChangeListener(new javax.swing.event.ChangeListener() {
|
||||||
public void stateChanged(javax.swing.event.ChangeEvent evt) {
|
public void stateChanged(javax.swing.event.ChangeEvent evt) {
|
||||||
jSpinner2StateChanged(evt);
|
jSpinner2StateChanged(evt);
|
||||||
|
@ -64,7 +64,7 @@ public class Exchange { //extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Account(double money, double shares) {
|
Account(double money, double shares) {
|
||||||
id = (Math.random() + (account_id.getNext()));
|
id = (random.nextDouble() + (account_id.getNext()));
|
||||||
orders = new HashMap();
|
orders = new HashMap();
|
||||||
this.money = money;
|
this.money = money;
|
||||||
this.shares = shares;
|
this.shares = shares;
|
||||||
@ -209,7 +209,8 @@ public class Exchange { //extends Thread {
|
|||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public Exchange() {
|
public Exchange() {
|
||||||
|
this.random = new java.util.Random(12);
|
||||||
|
|
||||||
this.qrlist = (new CopyOnWriteArrayList<>());
|
this.qrlist = (new CopyOnWriteArrayList<>());
|
||||||
|
|
||||||
// Create order books
|
// Create order books
|
||||||
@ -238,11 +239,7 @@ public class Exchange { //extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*public interface TimerEvent {
|
|
||||||
|
|
||||||
long timerEvent();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
void start() {
|
void start() {
|
||||||
timer.start();
|
timer.start();
|
||||||
}
|
}
|
||||||
@ -437,13 +434,15 @@ public class Exchange { //extends Thread {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Random random = new Random();
|
final Random random;
|
||||||
|
|
||||||
public int randNextInt() {
|
public int randNextInt() {
|
||||||
|
System.out.printf("Next int: %d\n", random.nextInt());
|
||||||
return random.nextInt();
|
return random.nextInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int randNextInt(int bounds) {
|
public int randNextInt(int bounds) {
|
||||||
|
System.out.printf("Next doub: %f\n",random.nextDouble());
|
||||||
return random.nextInt(bounds);
|
return random.nextInt(bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,15 +89,20 @@ public class Scheduler extends Thread {
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public long currentTimeMillis() {
|
public long currentTimeMillis1() {
|
||||||
|
|
||||||
long diff = System.currentTimeMillis() - last_time_millis;
|
long diff = System.currentTimeMillis() - last_time_millis;
|
||||||
|
// diff=121L;
|
||||||
last_time_millis += diff;
|
last_time_millis += diff;
|
||||||
this.current_time_millis += diff * this.multiplier;
|
this.current_time_millis += diff * this.multiplier;
|
||||||
|
|
||||||
return (long) this.current_time_millis;
|
return (long) this.current_time_millis;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long currentTimeMillis(){
|
||||||
|
return (long)this.current_time_millis;
|
||||||
|
}
|
||||||
|
|
||||||
static public String formatTimeMillis(long t) {
|
static public String formatTimeMillis(long t) {
|
||||||
Date date = new Date(t);
|
Date date = new Date(t);
|
||||||
@ -159,7 +164,7 @@ public class Scheduler extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
long t = event_queue.firstKey();
|
long t = event_queue.firstKey();
|
||||||
long ct = currentTimeMillis();
|
long ct = currentTimeMillis1();
|
||||||
|
|
||||||
//System.out.printf("Current CMP %d %d\n", ct, t);
|
//System.out.printf("Current CMP %d %d\n", ct, t);
|
||||||
|
|
||||||
@ -172,12 +177,13 @@ public class Scheduler extends Thread {
|
|||||||
TimerTask e = it.next();
|
TimerTask e = it.next();
|
||||||
long next_t = this.fireEvent(e);
|
long next_t = this.fireEvent(e);
|
||||||
|
|
||||||
this.addEvent(e, next_t+ct);
|
this.addEvent(e, next_t+t);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return (t - currentTimeMillis())/(long)this.multiplier;
|
return 0;
|
||||||
|
//return (t - currentTimeMillis1())/(long)this.multiplier;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +191,7 @@ public class Scheduler extends Thread {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
// this.current_time_millis=0;
|
||||||
while (!halt) {
|
while (!halt) {
|
||||||
|
|
||||||
long wtime = runEvents();
|
long wtime = runEvents();
|
||||||
|
@ -67,7 +67,7 @@ public class RandomTrader extends AutoTrader {
|
|||||||
public long timerTask() {
|
public long timerTask() {
|
||||||
sesim.Exchange.Account a = se.getAccount(account_id);
|
sesim.Exchange.Account a = se.getAccount(account_id);
|
||||||
long rc = this.doTrade();
|
long rc = this.doTrade();
|
||||||
System.out.printf("TT RC: %d\n",rc);
|
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
// return this.event();
|
// return this.event();
|
||||||
@ -114,7 +114,10 @@ public class RandomTrader extends AutoTrader {
|
|||||||
*/
|
*/
|
||||||
protected double getRandom(double min, double max) {
|
protected double getRandom(double min, double max) {
|
||||||
double r = se.randNextDouble();
|
double r = se.randNextDouble();
|
||||||
|
|
||||||
|
// System.out.printf("RD: %f", r);
|
||||||
|
// System.exit(0);
|
||||||
|
|
||||||
return (max - min) * r + min;
|
return (max - min) * r + min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user