Timing a process in a Thread
Im not so great with threads and im getting this strange behavior.
Im spawning a new thread for a load process.
I am just marking the start and end time with
System.currentTimeMillis() but im getting very strange results.
Processes that are obviously taking 10 seconds come up as taking .032 seconds or something equally not right.
Here is the code essentially:
// Start of load
long starttime = System.currentTimeMillis();
Program.log("\n\nLoading File...");
try{
Thread loadThread =new Thread(new Loader());
loadThread.start();
}catch(Exception e){
e.printStackTrace();
}
long endtime = System.currentTimeMillis();
// The thread process
publicvoid run(){// this is the thread runnable
long starttime = System.currentTimeMillis();
try{
// blocking load process
long endtime = System.currentTimeMillis();
System.out.println(end-start)
}catch(Exception e){}
}
Specifically the time is gotten with:
(((double)(endtime - starttime))/1000.0)
Nope
public void run() {
long startTime = System.currentTimeMillis();
try {
// There is rather long and blocking load process (video anaylsis) here
long endTime = System.currentTimeMillis();
System.out.println("Process took: " + (((double)(endtime - starttime))/1000.0) + " ms");
} catch(Exception e) {
// errors are caught and processed here
}
}
If you divide millis by 1000, you are printing "seconds", not "ms". So, are you interpreting your output correctly, even though you label it incorrectly?
Are you printing the time taken in the main thread, too? If so, are you differentiating them (label at beginning of println) so you know which is which in the output?
No the "ms" was just a mistake I typed in that reply (i wasnt copying from code).
Anyway, I found it. Thank you so much!
If someone hadnt pointed out the most obvious thing (the Method of Verbose Outputs, lol) I would have missed out on something important.
Im working with a 3rd party library for video loading.
I was doing
-start time
-load
-end time
-output # frames
and apparently the load process doesnt block - cause the load process doesnt load, lol.
In fact, when i query their Video class for anything (frames, frame rate, etc) for the first time THATS when they do the 30 second loading.
LAME.
thanks again.