Better schedulet

This commit is contained in:
7u83 2017-02-03 08:47:43 +01:00
parent 3039cee680
commit 2800dd7145
6 changed files with 27 additions and 19 deletions

View File

@ -55,7 +55,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
// int item_width = 10;
//int items = 350;
//long ntime = 0;
OHLCData data = new OHLCData(60000*15);
OHLCData data = new OHLCData(60000*30);
OHLCDataItem current = null;

View File

@ -335,7 +335,7 @@
<Component class="javax.swing.JSpinner" name="jSpinner2">
<Properties>
<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>
</Properties>
<Events>

View File

@ -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() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
jSpinner2StateChanged(evt);

View File

@ -64,7 +64,7 @@ public class Exchange { //extends Thread {
}
Account(double money, double shares) {
id = (Math.random() + (account_id.getNext()));
id = (random.nextDouble() + (account_id.getNext()));
orders = new HashMap();
this.money = money;
this.shares = shares;
@ -209,7 +209,8 @@ public class Exchange { //extends Thread {
* Constructor
*/
public Exchange() {
this.random = new java.util.Random(12);
this.qrlist = (new CopyOnWriteArrayList<>());
// Create order books
@ -238,11 +239,7 @@ public class Exchange { //extends Thread {
}
/*public interface TimerEvent {
long timerEvent();
}
*/
void start() {
timer.start();
}
@ -437,13 +434,15 @@ public class Exchange { //extends Thread {
return ret;
}
Random random = new Random();
final Random random;
public int randNextInt() {
System.out.printf("Next int: %d\n", random.nextInt());
return random.nextInt();
}
public int randNextInt(int bounds) {
System.out.printf("Next doub: %f\n",random.nextDouble());
return random.nextInt(bounds);
}

View File

@ -89,15 +89,20 @@ public class Scheduler extends Thread {
*
* @return
*/
public long currentTimeMillis() {
public long currentTimeMillis1() {
long diff = System.currentTimeMillis() - last_time_millis;
// diff=121L;
last_time_millis += diff;
this.current_time_millis += diff * this.multiplier;
return (long) this.current_time_millis;
}
public long currentTimeMillis(){
return (long)this.current_time_millis;
}
static public String formatTimeMillis(long t) {
Date date = new Date(t);
@ -159,7 +164,7 @@ public class Scheduler extends Thread {
}
long t = event_queue.firstKey();
long ct = currentTimeMillis();
long ct = currentTimeMillis1();
//System.out.printf("Current CMP %d %d\n", ct, t);
@ -172,12 +177,13 @@ public class Scheduler extends Thread {
TimerTask e = it.next();
long next_t = this.fireEvent(e);
this.addEvent(e, next_t+ct);
this.addEvent(e, next_t+t);
}
return 0;
} 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
public void run() {
// this.current_time_millis=0;
while (!halt) {
long wtime = runEvents();

View File

@ -67,7 +67,7 @@ public class RandomTrader extends AutoTrader {
public long timerTask() {
sesim.Exchange.Account a = se.getAccount(account_id);
long rc = this.doTrade();
System.out.printf("TT RC: %d\n",rc);
return rc;
// return this.event();
@ -114,7 +114,10 @@ public class RandomTrader extends AutoTrader {
*/
protected double getRandom(double min, double max) {
double r = se.randNextDouble();
// System.out.printf("RD: %f", r);
// System.exit(0);
return (max - min) * r + min;
}