NeverOnTimeSdnBhd / Delivery-Instances

2 stars 6 forks source link

Question on how to set execution time to 60 seconds #7

Open deminyau opened 3 years ago

deminyau commented 3 years ago

Hi, about basic simulation, for 5 customer scenario we can get the optimal output in less than 1 minute, but for N = 17 (example given in github), its take almost infinitely. So can u give us any suggestion/ methods used to terminate the loop when time is more than 60 seconds, currently we are using:

long start = System.currentTimeMillis(); long end = start + 60*1000; while (System.currentTimeMillis() < end) { //something }

However this method also result in a loop longer than 10 minutes. Please provide us guidance and suggestion. Thank you so much!

NeverOnTimeSdnBhd commented 3 years ago

Hi,

First, I am not sure why you say the code snippet you provide didn't work as I directly copy and try to run it seems it works fine for me.

Second, Please do some research on Google, there is a reason why I write

5. You might want to study Java.lang.System.nanoTime() or Instant with Duration for elapsed time calculation purpose.

in the update documentation instead of Java.lang.System.currentTimeMillis().

Sample reference: https://stackify.com/heres-how-to-calculate-elapsed-time-in-java/