Results 1 to 2 of 2
Thread: Time and Thread
- 05-12-2010, 01:16 PM #1Member
- Join Date
- May 2010
- Rep Power
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
- 09-19-2010, 04:51 PM #2Member
- Join Date
- Sep 2010
- Rep Power
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.Volker Berlin
- By javatrek2020 in forum Jobs OfferedReplies: 3Last Post: 08-23-2011, 12:46 PM
- By Fleur in forum New To JavaReplies: 18Last Post: 11-17-2009, 01:57 PM
- By karthikeyan_raju in forum Threads and SynchronizationReplies: 2Last Post: 10-06-2009, 02:40 AM
- By verbazon in forum New To JavaReplies: 1Last Post: 04-13-2009, 01:06 AM