• Post Reply Bookmark Topic Watch Topic
  • New Topic

System.currentTimeMillis()  RSS feed

 
Kuro Kagami
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go home java you are drunk,
"
while (true) {
long ms = System.currentTimeMillis();
long result = System.currentTimeMillis() - ms;
if (result > 0)
log("[1] LAG: " + result + "ms");
}
"

Output:
"
[1] LAG: 16ms
[1] LAG: 16ms
[1] LAG: 16ms
[1] LAG: 16ms
[1] LAG: 15ms
[1] LAG: 15ms
[1] LAG: 16ms
[1] LAG: 16ms
[1] LAG: 16ms
[1] LAG: 16ms
[1] LAG: 16ms
[1] LAG: 15ms
[1] LAG: 16ms
[1] LAG: 16ms
[1] LAG: 15ms
[1] LAG: 15ms
[1] LAG: 15ms
[1] LAG: 15ms
[1] LAG: 16ms
[1] LAG: 16ms
[1] LAG: 16ms
[1] LAG: 1ms
[1] LAG: 16ms
[1] LAG: 16ms
[1] LAG: 16ms
"
^Had the program running for about 10 seconds

Can anyone explain this?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

What is the "this" that needs explaining?
 
Kuro Kagami
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Welcome to the Ranch

What is the "this" that needs explaining?


Sorry, but do i even need to tell you?
It should'nt print out anything more than 0ms, but it prints out 16.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kuro Kagami wrote:Sorry, but do i even need to tell you?

Yes. Yes, you do. And you might also want to read about using honey rather than vinegar when responding to people who are taking time out from their Sunday day off to help you.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might also want to study the Observer effect.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And you might also want to read the documentation for that method where it says, "the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds.," and use that to check your assumption that it "shouldn't" print out anything more than 0 ms.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!