Time and Thread
I want to calculate the ElapsedTime and ThreadTime to the particular Thread(current Thread). In c++ I am using QueryPerformanceFrequency() and GetThreadTimes() to get the all the necessary information.
I am new to JAVA. Is there any similar function available in JAVA to calculate the ElasedTime and ThreadTime? Please expalin me with some code sample.
Retrieves timing information for the specified thread.
BOOL WINAPI GetThreadTimes(
__in HANDLE hThread,
__out LPFILETIME lpCreationTime,
__out LPFILETIME lpExitTime,
__out LPFILETIME lpKernelTime,
__out LPFILETIME lpUserTime
A handle to the thread whose timing information is sought. The handle must have the THREAD_QUERY_INFORMATION or THREAD_QUERY_LIMITED_INFORMATION access right. For more information, see Thread Security and Access Rights.
Windows Server 2003 and Windows XP/2000: The handle must have the THREAD_QUERY_INFORMATION access right.
A pointer to a FILETIME structure that receives the creation time of the thread.
A pointer to a FILETIME structure that receives the exit time of the thread. If the thread has not exited, the content of this structure is undefined.
A pointer to a FILETIME structure that receives the amount of time that the thread has executed in kernel mode.
A pointer to a FILETIME structure that receives the amount of time that the thread has executed in user mode.
The QueryPerformanceCounter function retrieves the current value of the high-resolution performance counter.
__out LARGE_INTEGER *lpPerformanceCount
Pointer to a variable that receives the current performance-counter value, in counts.
If the function succeeds, the return value is nonzero
Thanks in advance
No, in Java you can't do it. The only option do you have is to call the Windows API directly. Because you already know it from C++ it should not a large problem for you. To call a native API from Java the best solution is to use JNA (Java Native Access). The most important part of the Windows API is already define. If not you can request it or add it self. It is Open Source.
You does not need to write a single line in C or C++. This is different to JNI.