Skip to content

Instantly share code, notes, and snippets.

@redsquirrel
Created October 20, 2008 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save redsquirrel/18193 to your computer and use it in GitHub Desktop.
Save redsquirrel/18193 to your computer and use it in GitHub Desktop.
import java.util.Date;
public class Worker implements Runnable{
long executionMillis = -1;
public void run() {
for(int i=0; i<100; i++) {
executionMillis = (new Date()).getTime();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public long getIdleMillis() {
if (executionMillis == -1) {
return 0;
}
return (new Date()).getTime() - executionMillis;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment