Results 1 to 2 of 2
Thread: Time and Thread
- 05-12-2010, 01:16 PM #1
Member
- Join Date
- May 2010
- Posts
- 1
- Rep Power
- 0
Time and Thread
Hi,
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.
API function:
1. GetThreadTimes()
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
);
Parameters
hThread [in]
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.
lpCreationTime [out]
A pointer to a FILETIME structure that receives the creation time of the thread.
lpExitTime [out]
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.
lpKernelTime [out]
A pointer to a FILETIME structure that receives the amount of time that the thread has executed in kernel mode.
lpUserTime [out]
A pointer to a FILETIME structure that receives the amount of time that the thread has executed in user mode.
2. QueryPerformanceCounter()
The QueryPerformanceCounter function retrieves the current value of the high-resolution performance counter.
Syntax
BOOL QueryPerformanceCounter(
__out LARGE_INTEGER *lpPerformanceCount
);
Parameters
lpPerformanceCount [out]
LARGE_INTEGER
Pointer to a variable that receives the current performance-counter value, in counts.
Return Value
BOOL
If the function succeeds, the return value is nonzero
Thanks in advance
Mani.
- 09-19-2010, 04:51 PM #2
Member
- Join Date
- Sep 2010
- Posts
- 33
- Rep Power
- 0
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
www.inetsoftware.de
Similar Threads
-
JAVA Programmers Wanted - Full-Time and Part-Time Positions open
By javatrek2020 in forum Jobs OfferedReplies: 3Last Post: 08-23-2011, 12:46 PM -
Running thread a second time
By Fleur in forum New To JavaReplies: 18Last Post: 11-17-2009, 12:57 PM -
need info on running thread during a particular time interval alone
By karthikeyan_raju in forum Threads and SynchronizationReplies: 2Last Post: 10-06-2009, 02:40 AM -
Class Time - represents time of day
By verbazon in forum New To JavaReplies: 1Last Post: 04-13-2009, 01:06 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks