Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java application not work,when i update my-demo-file.tmp #265

Closed
luoy1991 opened this issue Sep 10, 2020 · 1 comment
Closed

java application not work,when i update my-demo-file.tmp #265

luoy1991 opened this issue Sep 10, 2020 · 1 comment

Comments

@luoy1991
Copy link

luoy1991 commented Sep 10, 2020

execution environment

docker run -it --name mytest -d registry.cn-shanghai.aliyuncs.com/lvgu/python3:latest
jdk-8u251-linux-x64.tar.gz
libfaketime master branch

test.jar code

package test;

import java.time.*;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class a {
private static final int NO_DELAY = 0;

public static void main(String[] args) {
Runnable printCurrentDateTime = () -> System.out.println(LocalDateTime.now());

Executors
  .newSingleThreadScheduledExecutor()
  .scheduleAtFixedRate(printCurrentDateTime, NO_DELAY, 1, TimeUnit.SECONDS);

}
}

create any file with December 24th, 2009, 12:34:56 as timestamp

touch -t 0912241234.56 /app/my-demo-file.tmp

run test.jar printing the current time

LD_PRELOAD=/usr/local/lib/faketime/libfaketime.so.1 \
FAKETIME='%' FAKETIME_FOLLOW_FILE=/app/my-demo-file.tmp \
FAKETIME_DONT_FAKE_MONOTONIC=1 \
FAKETIME_DONT_RESET=1 \
java -jar test.jar

console output

2009-12-24T12:34:56.338
2009-12-24T12:34:57.308
2009-12-24T12:34:58.301
2009-12-24T12:34:59.301
2009-12-24T12:35:00.300
2009-12-24T12:35:01.300
2009-12-24T12:35:02.300
2009-12-24T12:35:03.300
2009-12-24T12:35:04.299
2009-12-24T12:35:05.328
2009-12-24T12:35:06.299

now, while the above is running, change the file's timestamp

touch -t 2002290123.45 /app/my-demo-file.tmp

console output

2009-12-24T12:35:07.298
2009-12-24T12:35:08.300
2009-12-24T12:35:09.299
2009-12-24T12:35:10.303
2009-12-24T12:35:11.301
2009-12-24T12:35:12.300
2009-12-24T12:35:13.299
2009-12-24T12:35:14.303
2009-12-24T12:35:15.301

@wolfcw
Copy link
Owner

wolfcw commented Feb 18, 2021

does it work outside docker?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants