VM-level date simulation

A

Andrea Marchesani

Hi,
how can I simulate a system date change in the Java VM leaving the
system date unchanged?
I'm working on Solaris, and usually I change the system date via date
-u to simulate this, but doing so every process gets the changed date.
I'm looking for a way to change date only for a specific java process.
I'd like to override System.currentTimeMillis(), but unfortunately I
can't.

Any help would be greatly appreciated.

Andrea
 
J

Jared Dykstra

Hi,
how can I simulate a system date change in the Java VM leaving the
system date unchanged?
I'm working on Solaris, and usually I change the system date via date
-u to simulate this, but doing so every process gets the changed date.
I'm looking for a way to change date only for a specific java process.
I'd like to override System.currentTimeMillis(), but unfortunately I
can't.

Any help would be greatly appreciated.

Andrea

I'm not too optimistic that this can be done.

How the VM's system clock is implemented is not defined by any spec as
far as I know. I checked with the O'Reilly Fishbowl book--which is
vague at best--and of course it made no mention. If you were the
implementer of a VM or KVM this probably would be an easy feature to
add.

There is only one system clock in Solaris, so I don't think there is a
way where the effects of changing it could isolated to only one
process. There may, however, be a different way to set the system
clock in such a way that most threads are not notified of the
change...But I am being completely hypothetical here.

You might want to post on a Solaris newsgroup to see if there are more
options when it comes to setting the system time.
 
D

Daniel Bonniot

how can I simulate a system date change in the Java VM leaving the
system date unchanged?

I don't think this is supported by the JVM itself. However, it should be
possible to do it at the OS level: you could probably write a
replacement function to the function that reads the system date in the
libc, and make it replace to standard function for the JVM process,
using the LD_PRELOAD environment variable. I know this technique is used
by tools to replace the standard malloc function, in order to monitor
memory usage.

You could also google on tools that do this. With the y2k bug fury, I
would be very surprised if zillions of such utilities have not been
written for Unix.

Daniel
The Nice programming language: http://nice.sf.net
 
T

Tim Tyler

In comp.lang.java.programmer Jared Dykstra said:
(e-mail address removed) (Andrea Marchesani) wrote in message news:<[email protected]>...

I'm not too optimistic that this can be done.

Sun's JVM license does not permit modification of the system classes.

If you don't like them, your choices are to replace them, or wrap them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top