0

I am creating a program that makes a calculation every minute. I don't know exactly how to do this efficiently, but this is some pseudo code I have written so far:

 stockCalcTimerH = System.currentTimeMillis() - 1; stockCalcTimerI = stockCalcTimerH; stockCalcTimer = System.currentTimeMillis(); if (stockCalcTimerI < stockCalcTimer) { *do calcuations* stockCalcTimerI + 60000; 

When I print both values out on the screen, it comes out as this:

stockCalcTimerI = 1395951070595 stockCalcTimer = 1395951010596

It only subtracts the number, and doesn't add the 60000 milliseconds... I'm kind of new to Java, but any feedback helps.

Thanks for reading!!

2
  • I lied it worked in the first place... Commented Mar 27, 2014 at 20:30
  • 1
    What do you mean by stockCalcTimerI + 60000; ? If you mean stockCalcTimerI += 60000; then ok never adds 60000 milliseconds. Commented Mar 27, 2014 at 20:40

2 Answers 2

2
stockCalcTimerI + 60000; 

The new value never gets assigned to a variable.

Change that to:

stockCalcTimerI += 60000; 

Which is the same as

stockCalcTimerI = stockCalcTimerI + 60000; 
Sign up to request clarification or add additional context in comments.

Comments

0

You can use java.util.Timer class to schedule runs.

TimerTask task = new TimerTask() { @Override public void run() { // do calculations } }; int delay = 0; // no delay, execute immediately int interval = 60*1000; // every minute new Timer().scheduleAtFixedRate(task, delay, interval); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.