Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

thread time  RSS feed

 
Adamu Yifru
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why does this code give me the same milleseconds?
Date mille = new Date();
System.out.print(mille.getTime());
someThread.sleep(100);
system.out.print(mille.getTime());
The first out.print should be 100ms smaller than the first but it is not.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Date object represents a fixed instant in time -- here, the instant you create it. For a given instance of Date, Date.getTime() will always return the same value (until someone deliberately calls a method that changes the point in time that object represents.)
You may be looking for the System.getCurrentTimeMillis() method, which returns the current time in milliseconds.
 
Adamu Yifru
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks that solves a lot of my threading problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!