Results 1 to 2 of 2

Thread: Time and Thread

  1. #1
    bmvasakan is offline Member
    Join Date
    May 2010
    Posts
    1
    Rep Power
    0

    Default 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.

  2. #2
    Horcrux7 is offline Member
    Join Date
    Sep 2010
    Posts
    33
    Rep Power
    0

    Default

    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

  1. Replies: 3
    Last Post: 08-23-2011, 12:46 PM
  2. Running thread a second time
    By Fleur in forum New To Java
    Replies: 18
    Last Post: 11-17-2009, 12:57 PM
  3. need info on running thread during a particular time interval alone
    By karthikeyan_raju in forum Threads and Synchronization
    Replies: 2
    Last Post: 10-06-2009, 02:40 AM
  4. Class Time - represents time of day
    By verbazon in forum New To Java
    Replies: 1
    Last Post: 04-13-2009, 01:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •