Question

Is it possible to slow down time in the Java virtual machine according to CPU usage by modification of the source code of OpenJDK? I have a network simulation (Java to ns-3) which consumes real time, synchronised loosely to the wall clock. However, because I run so many clients in the simulation, the CPU usage hits 100% and hard guarantees aren't maintained about how long events in the simulator should take to process (i.e., a high amount of super-late events). Therefore, the simulation tops out at around 40 nodes when there's a lot of network traffic, and even then it's a bit iffy. The ideal solution would be to slow down time according to CPU, but I'm not sure how to do this successfully. A lesser solution is to just slow down time by some multiple (time lensing?).

If someone could give some guidance, the source code for the relevant file in question (for Windows) is at http://pastebin.com/RSQpCdbD. I've tried modifying some parts of the file, but my results haven't really been very successful.

Thanks in advance,
Chris

Was it helpful?

Solution

You might look at VirtualBox, which allows one to Accelerate or slow down the guest clock from the command line.

OTHER TIPS

I'm not entirely sure if this is what you want but, with the Joda-time library you can stop time completely. So calls to new Date() or new DateTime() within Joda-time will continously return the same time.

So, you could, in one Thread "stop time" with this call:

DateTimeUtils.setCurrentMillisFixed(System.currentTimeMillis());

Then your Thread could sleep for, say, 5000ms, and then call:

// advance time by one second
DateTimeUtils.setCurrentMillisFixed(System.currentTimeMillis() + 1000);

So provided you application is doing whatever it does based on the time within the system this will "slow" time by setting time forwards one second every 5 seconds.

But, as i said... i'm not sure this will work in your environment.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top