Is it possible that your system clock is jumping?
Eclipse System.currentTimeMillis() , currentTimeMillis ( System.nanoTime() .)
long timeout = System.currentTimeMillis() + 500;
while (System.currentTimeMillis() < timeout) {
eventPtr = OS.gdk_event_get ();
if (eventPtr != 0) {
break;
} else {
try {Thread.sleep(50);} catch (Exception ex) {}
}
}
, , JVM ?", JBoss Byteman , .
Foo.java:
public class Foo {
public void test1() {
long timeout = System.currentTimeMillis() + 500;
int i = 0;
while (System.currentTimeMillis() < timeout) {
System.out.println(i++);
try {Thread.sleep(50);} catch (Exception ex) {}
}
}
public static void main(final String ... args) throws Exception {
new Foo().test1();
}
}
sleeper.btm:
RULE counter
CLASS Foo
METHOD test1
AT ENTRY
IF TRUE
DO createCountDown($0, 5)
ENDRULE
RULE sleeper
CLASS Foo
METHOD test1
AT INVOKE Thread.sleep()
IF countDown($0)
DO RETURN
ENDRULE
Byteman script:
$ ~/Downloads/byteman-download-2.1.0/bin/bmjava.sh -l ./sleeper.btm Foo
0
1
2
3
4
5
:
$ java Foo
0
1
2
3
4
5
6
7
8
9