Calculate elapse time of a Java thread  before execution

Hi,
I would like to enquire how can I calculate the elapse time of a Java thread BEFORE this thread is executiing or running.?
I wish to estimate the elapsed time of each Java thread before execution to better schedule these threads to run on multiple processors for load balancing testing.
Please help
-meileng-[                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

You can grab the system time in the initiating thread immediately before calling start(), and as the first step in run() in the new thread.
However, this measurement is utterly meaningless, as it can vary between architectures or even between consecutive runs on the same box. Furthermore, even once a thread starts, it may do nothing more than that one grab-the-system-time instruction before it get swapped out for a theoretically unbounded amount of time.
By definition, if you spawn multiple threads in Java, you don't know or care which one get CPU time when, except as you control by syncing, sleep, wait, notify, notifyAll, and whatever control priorities give you. Additionally, you don't know when the OS will give your VM cycles, and on multi-CPU machines, you don't know how many CPUs it will get when it does get cycles.

Similar Messages

  • Calculate elapsed time with VBS/PowerShell

    I'm trying to calculate MDT task sequence execution time. What could be the best method for this? It can be PowerShell or VBS code.
    Plan is to execute a script at the beginning of a task sequence that stores a start time in variable and at the end of task sequence execute another script that reads that start time from variable and calculates total time taken and saves it to another variable.
    I have tried few VB scripts but I have had some odd results some times with them. We are using 24 hour clock and it might have caused some problems for my previous scripts.

    I think you can enable monitoring and then validate from a console the elapsed time.  It's a slow morning so I also wrote something that would work in powershell for fun -
    param($start, $stop)
    $file = $(get-date -f mmddyyyy) + '_timer.log'
    $filepath = "$env:temp\$file"
    function Start-Time {
    if(test-path $filepath){
    Remove-Item -path $filepath -force
    else{
    New-Item -ItemType File -Path $filepath
    function Calculate-Time {
    if(!(Test-Path $filepath)){
    Write-Error "Calculate-Time: ERROR - Timer file was not found at path $filepath. Please validate you are running this script with the -start parameter before running with the -finish parameter."
    else{
    $fileinfo = gci $filepath
    $stime = $fileinfo.CreationTime
    $etime = (Get-Date)
    $time = New-TimeSpan -start $stime -end $etime
    return "Time from creation of file to finish is $time."
    function Main{
    if($start){
    Start-Time | Out-Null
    if($stop){
    Calculate-Time | Out-Null
    else{
    return "Main: You must provide a parameter to use this tool. Parameters are -start to start the timer or -stop to end the timer and calculate time elapsed."
    Main
    You can modify filepath at the top to set where it saves the file.  What it does is creates a file in the environment temp directory and then uses that file creation time against current date/time to give you a duration.  Parameter -start creates
    the file starting the timer and parameter -stop finds that file and calculates the difference in time between creation and current time.  Either way I needed to get some powershell practice and maybe this will help you. 
    Ryan

  • How to calculate elapsed time(including time and date)?

    Hi all,
    I want to realize a function that can calculate the elapsed time which include time and date.Below is my thought:get the current time and date and store it to a .txt file then using the latest time and date subtract the time and date stored in the .txt file.how can realize it using the simplest way?I'm using LV7.1.

    Hi Idragon,
    you can do it like this.
    Mike
    Attachments:
    DateTime.PNG ‏12 KB

  • How to calculate elapsed time based on user input

    I'm not sure what to do next in this program. Basically, I'm not sure exactly how to get the time to output accurately, as in what forumla I should be using.
    This is the question:
    What comes 13 hours after 4 o'clock? Create an ElaspedTimeCalculator application that prompts the user for a starting hour, whether it is am or pm, and the number of elapsed hours. The application then displays the time after that many hours have passed. Application output should look similar to:
    Enter the starting hour: 7
    Enter am or pm: pm
    Enter the number of elapsed hours: 10
    The time is: 5:00 amHere's the code I have so far:
    import java.util.Scanner;
    public class ElapsedTimeCalculator
         public static void main(String[] args)
              int starting_hour;
              int starting_minutes; /*This is added in case the user wants to add minutes as well.*/
              String am_or_pm;
              int elapsed_hours;
              int elasped_minutes;
              int time_hours;
              int time_minutes;
              System.out.println("Welcome. This application will give you the time based on your input.");
              System.out.println(" ");
              Scanner input = new Scanner(System.in);
              System.out.print("Enter the starting hour: ");
              starting_hour = input.nextDouble();
              System.out.print("Enter the starting minutes: ");
              starting_minutes = input.nextDouble();
              System.out.print("Enter either 'am' or pm': ");
              am_or_pm = input.nextString();
              System.out.print("Enter the number of elapsed hours: ");
              elapsed_hours = input.nextDouble();
              input.close();
              time_hours =
              time_minutes = 
              if(am_or_pm = "am" || am_or_pm = "a.m." || am_or_pm = "AM" || am_or_pm = "A.M.")
                   System.out.println("The time is " + time_hours + ":" + time_minutes + "am");
              if(am_or_pm = "pm" || am_or_pm = "p.m." || am_or_pm = "PM" || am_or_pm = "P.M.")
                   System.out.println("The time is " + time_hours + ":" + time_minutes + "pm");
    }To calculate time_hours should I just calculate this by adding the elapsed hour to the starting hour? I doubt it will be accurate for all situations.
    Same for the time_minutes For example, if the starting minutes and the elapsed minutes were 50, it would be greater than 60. Also, not sure if it makes sense to separate hours and minutes like this, it's not required to in the question. I initally thought it would be easier to approach like this instead of allowing the user to input a double for the starting hour. ex. 5.7
    I get the feeling that this is extremely simple, but nonetheless, I'm stuck, so any help would be appreciated.

    Well thanks to both of you. I did a little reading up on the modulus operator and coupled it with some logic (although, truthfully, I'm not really using to there actually being an application for the remainder of a division operation, since it's never really used very much in any of my Math courses) and the hours portion works perfectly now:
    import java.util.Scanner;
    public class ElapsedTimeCalculator
         public static void main(String[] args)
              int starting_hour;
              //int starting_minutes; /*This is added in case the user wants to add minutes as well.*/
              String am_or_pm;
              int elapsed_hours;
              //int elasped_minutes;
              System.out.println("Welcome. This application will give you the time based on your input.");
              System.out.println(" ");
              Scanner input = new Scanner(System.in);
              System.out.print("Enter the starting hour: ");
              starting_hour = input.nextInt();
              //System.out.print("Enter the starting minutes: ");
              //starting_minutes = input.nextInt();
              System.out.print("Enter either 'am' or pm': ");
              am_or_pm = input.next();
              System.out.print("Enter the number of elapsed hours: ");
              elapsed_hours = input.nextInt();
              input.close();
              int time_hours = 0;
              //int time_minutes;
              String meridien;
              if(am_or_pm.equals("am"))
                   time_hours = (starting_hour + elapsed_hours) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              else if(am_or_pm.equals("am"))
                   time_hours = (starting_hour + elapsed_hours) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              else if(am_or_pm.equals("AM"))
                   time_hours = (starting_hour + elapsed_hours) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              else if(am_or_pm.equals("A.M."))
                   time_hours = (starting_hour + elapsed_hours) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              else if(am_or_pm.equals("pm"))
                   time_hours = (starting_hour + elapsed_hours + 12) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              else if(am_or_pm.equals("p.m."))
                   time_hours = (starting_hour + elapsed_hours + 12) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              else if(am_or_pm.equals("PM"))
                   time_hours = (starting_hour + elapsed_hours + 12) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              else if(am_or_pm.equals("P.M."))
                   time_hours = (starting_hour + elapsed_hours + 12) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              if(time_hours < 12)
                   meridien = "A.M.";
                   System.out.println("The time is: " + time_hours + ":00 " + meridien);
              else if(time_hours > 12)
                   meridien = "P.M.";
                   System.out.println("The time is: " + time_hours + ":00 " + meridien);
    }Now the only thing is the minutes. My teacher did say she wants the user to have the option to input minutes also if he/she desires, so I do need it. However, the only problem is that if say the user inputs a "starting minute" of 14 for example, and 66 minutes elapsing, then (14 + 66) int/ 60 = 1r20 but using the modulus operator would only give me 20. So how will I be able to add any extra hours if it is necessary?

  • To calculate elapsed time between two timestamp attributes

    Hello,
    I have two timestamp attributes (create_tmstmp & elapsed_tmstmp) in a table.
    It has two rows and I need the difference in seconds between these two attributes.
    The below query is returning negative value and incorrect value.
    Any help is appreciated.
    Row 1:
    Create_tmstmp : 2/2/2010 9:53:15.832 PM
    Elapsed_tmstmp : 2/3/2010 9:49:47.527 AM
    Row 2:
    Create_tmstmp : 2/3/2010 5:35:47.614 AM
    Elapsed_tmstmp : 2/3/2010 11:03:15.937 AM
    Select
    ( (extract(day from elapsed_tmstmp )-extract(day from create_tmstmp))*86400+
    (extract(hour from elapsed_tmstmp )-extract(hour from create_tmstmp))*3600+
    (extract(minute from elapsed_tmstmp)-extract(minute from create_tmstmp))*60+
    (extract(second from elapsed_tmstmp)-extract(second from create_tmstmp))*1000) completed_tmstmp
    From table_a;
    The output is :
    completedtmstmp_
    74655
    -11997
    Thanks.
    Edited by: solsam on Feb 4, 2010 11:57 AM

    hi,
    The problem with cast to date is
    SQL> select to_char(cast(to_timestamp('2/2/2010 9:53:15.832 PM','mm/dd/yyyy hh:mi:ss.ff pm') as dat
    e),'mm/dd/yyyy hh:mi:ss pm') from dual
    2 ;
    TO_CHAR(CAST(TO_TIMEST
    02/02/2010 09:53:16 pm
    so cast rounds it up, resulting in:
    SELECT (
    CAST (TO_TIMESTAMP ('2/2/2010 9:53:15.832 PM', 'mm/dd/yyyy hh:mi:ss.ff pm') AS DATE)
    - CAST (TO_TIMESTAMP ('2/2/2010 9:53:14.432 PM', 'mm/dd/yyyy hh:mi:ss.ff pm') AS DATE)
    * 86400 x
    FROM DUAL
    X
    2
    A more exact answer would use, to_char and to_date to convert :
    SELECT (
    TO_DATE (TO_CHAR (TO_TIMESTAMP ('2/2/2010 9:53:15.832 PM', 'mm/dd/yyyy hh:mi:ss.ff pm'),
    'mm/dd/yyyy hh:mi:ss pm'),
    'mm/dd/yyyy hh:mi:ss pm')
    - TO_DATE (TO_CHAR (TO_TIMESTAMP ('2/2/2010 9:53:14.432 PM', 'mm/dd/yyyy hh:mi:ss.ff pm'),
    'mm/dd/yyyy hh:mi:ss pm'),
    'mm/dd/yyyy hh:mi:ss pm')
    * 86400 x
    FROM DUAL
    X
    1
    Edit:
    Massimo Ruocchio's answer actually works better.
    -AC
    Edited by: user12026137 on Feb 9, 2010 12:45 PM

  • Java Thread.. System Clock gets slower..

    Hello All!
    I have never came accross such problem in my last 4 years of java development but right now its sucking my brain like any thing..
    Let me clerify what my application is doing.
    A node which is basically thread is executed and as it performs its job it is stopped by breaking the while loop like logic and then a method isRunnable() is called to calculate the time to run the thread again on the basis of pre-defined schedule (e.g. after 1 minute). so what i was doing in this method i was calling wait (sheduledMinutes*60*1000).
    There are multiple nodes which can be run in parallel. Problem occured when some nodes started immediately or after a time much shorter than the value defined in wait() method.
    So as an alternative way i decided to not rely on wait() and wrote my own implementaion i.e. i call wait(1000) in isRunnable() and the check if the current system time is less then the scheduled time. But it didn't work either.
    The problem revealed when i printed the valued of current time taken by the system and the scheduled one. The System clock gives the current time which is less than the actual System time shown on windows clock. I dont know why but it seems like as my threads continue to run the system clock gets slower or something and returns an old time. Hence nodes start immediately.
    Any solution to this problem would be highly appreciable.
    Regards,

    Well yeah u r right. I figured it out that it was just my threads running slowly. But the threads ran immediately there was another reason for that. My threads were waiting for the sheduled minutes to run again. In the mean while if i presed the stop button to stop the thread i was just setting the stop variable value to true. Which was basically the check in the while loop in run method. U can notice the thread still sleeping due to the call to wait method. And then if again mean while i press start button i called System.gc(). and then pass the current thread to new Thread like Threa t = new Thread(node); t.start();
    Now u can c another thread has been created but the last one was not collected by the garbage collector as it was still waiting and doing something ofcourse not dead. So now when new thread stops these was a possiblity of last thread ( one in waiting state) to run according to schedule and it make the current thread run immediately.
    I hope u can understand how difficult it was for me to figure this thing out :)
    But after 3/4 hours hair tearing i got the bug and then when i was stopping a thread i infact broke the waiting loop as well. Now the thread was dead and collected by garbage collector before new thread could start :)
    Hhhhhhhhhhhhhh sometimes programmign really sucks.
    Have fun. and thanx for ur concern..
    Regards

  • Date Utility - calc age, elapsed time...

    I need to calculate elapsed time between 2 dates, for example calc age based on DOB and Today. There must be a utility out there somewhere (free!). I'm sure I'm not the first one with this requirement.

    try this
    import java.util.*;
    public class DateSub {
      public static void main(String [] args) {
        Calendar cal = Calendar.getInstance();
        cal.set (1970,0,1);
        long age = cal.getTime().getTime();
        age = System.currentTimeMillis() - age;
        System.out.println ("age = " + age + " milliseconds" );
        age /= 1000;
        System.out.println ("age = " + age + " seconds" );
        age /= (3600*24);
        System.out.println ("age = " + age + " days" );
        long years = age/(365);
        long days = age % 365;
        System.out.println ("age = " + years + " years " + days + " days");
    }

  • How can I get the elapse time for execution of a Query for a session

    Hi ,
    How can I get the elapse time for execution of a Query for a session?
    Example - I have a report based on the procedure ,when the user execute that it takes say 3 min. to return rows.
    Is there any possible way to capture this session info. for this particular execution of query along with it's execution elapse time?
    Thanks in advance.

    Hi
    You can use the dbms_utility.get_time tool (gives binary_integer type value).
    1/ Initialize you time and date of beginning :
    v_beginTime := dbms_utility.get_time ;
    2/ Run you procedure...
    3/ Get end-time with :
    v_endTime := dbms_utility.get_time ;
    4/ Thus, calculate elapsed time by difference :
    v_elapsTime := v_endTime - v_beginTime ;
    This will give you time elapsed in of 100th of seconds...
    Then you can format you result to give correct print time.
    Hope it will help you.
    AL

  • Log of Time to Start JAVA

    Hello ALL,
    I WOULD LIKE TO KNOW HOW TO DISCOVER THE ELAPSED TIME
    FOR THE STOP/START OF JAVA PROCESS
    Is the one transaction specificed in XI or S.O?
    Kind Regards.

    Hi Produção,
    you can find out the elapsed time of the java server process via the SAP management console (MMC), under AS Java Process Table
    Best Regards,
    Christian

  • !!!-Need help for terminating a Java thread in real time

    Hi everyone!
    I use J2SDK1.4.1 on a Unix platform.
    I want to terminate (or stop) a running java thread, which is dealing with time consuming tasks, in real-time (for example: the delay before the thread is terminated can't beyond one second), However, I don't know which techniques I can use to make sure the previous (or old) running java threads have been terminated?
    Could you please give me any help if you can?
    Any suggestion or reply will be kindly appreciated!
    Thanks!

    Thanks very much, jverd !
    I do set a flag that the thread should periodically check !
    Well, the scenario is like this:
    1. the thread read line by line (using BufferedReader) string from a probably huge-size file
    2. analyse each string read from the file if required (some strings may be omitted based on the user's operations), the analyzing process is a time-consuming task, and the analysing process may be terminated at any time the user want.
    3. record only the strings that have been analyzed by the previous process into a recording file
    The problem I meet is as follows: (Here, I suppose that it should take at least 30 seconds to finish analyse all the strings in a given huge file )
    1. the user start the analysing process, and run it for only 5 seconds,then stop the analyzing.
    2. the user start the analysing process again from the begining of the file(analyse the strings within the same file as previous step), and then stop the analysing process at 10 second. (it means, this time the analysing process is running for 10 seconds, still haven't finish analyse all the strings in the file).
    Once I open the record file, I saw some of the strings in the recording file have been repetitively record for 2 times, and the repetitive strings are just the strings the analysing time from at 5 second to at 10 second.
    And the repetitive times are depend on how many time the user start and stop the analysing process using the same file. for example, based on the above two steps, the user do the third step as follow:
    3. the user start the analysing process once again, analyse the same file,too. And run it for 15 seconds
    This time open the recording file, this time I saw some of the strings have been repetitively record for 3 times, and the repetitive strings are just the strings the analysing time from at 10 second to at 15 second.
    So, I guess the problem is probably because the previous analysing threads haven't been terminated completely, or say they just are blocked or set as inactive etc., then when the next time start the analysing process, the old threads will be reactive,and rerun ffrom the last time they are blocked.
    I hope you had catched what I mean, if you not, please ust let me know, I'll try to explain it again.
    Thanks once again!

  • Java Thread.sleep(timeout) is influenced by changes to System time on Linux

    Java Thread.sleep(timeout) is influenced by changes to System time on Linux
    bugId : 6311057
    I encountered this problem in redhat6/ jdk 1.6

    890651 wrote:
    Java Thread.sleep(timeout) is influenced by changes to System time on Linux
    bugId : 6311057
    I encountered this problem in redhat6/ jdk 1.6At least half the time I use it, I'd want it to be, the other half I wouldn't care.
    What are you doing with it where this might be a problem?
    Changing the system clock abruptly can cause all kinds of problems with your system anyway, because various background activities etc. often depend on file dates. Wherever possible use the "skew" method to adjust your system clock, rather than just plonking in a new value, especially if you are setting the clock backwards.

  • Java Thread implementation

    Here is my code, I would like to know if I implement my threads nicely here, I am worrying those threads are still alive, they should be interrupted. but why I got different thread ID when i resume it?
    // Two player board game play in turn. Human plays first as red, the computer plays
    // second as blue. I used thread here for repainting the applet, because the computer
    // evaulation function is quite slow, the gui won't draw human player's move until it
    // finishs calculating computer's move. the solution i use is interrupting the current
    // thread, let the gui repaint before calculating the computer move.
    // Board.java
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Board extends Canvas implements Runnable, MouseListener {
        private Thread main;
        private int state = 0;
        private double aMove = 0;
        public void init() {
            addMouseListener(this);
        public void run() {
            removeMouseListener(this);
            main.interrupt();
            main = null;
            repaint();
            // calculate computer's move, then making move
            // this is a slow evalution function goes here
            for (int i = 0; i <10000000; i++) {
                aMove = Math.pow(0.1,1000000000);
            state = 1;
            repaint();
            System.out.println("Blue makes a move on postion " + aMove);
            state = -1;
            addMouseListener(this);
        public void paint(Graphics g) {
            System.out.println("paint");
            if (state == 1) {
                g.setColor(Color.blue);
                g.fillOval(0, 0, 20, 20);
            if (state == -1) {
                g.setColor(Color.red);
                g.fillOval(0, 0, 20, 20);
        public void mouseReleased(MouseEvent e) {
            // human player makes a move on postion 0;
            aMove = 0;
            System.out.println("Red makes a move on postion " + aMove);
            state = -1;
            repaint();
            // Why the following gives me different thread here every time?
            main = new Thread(this);
            System.out.println("Thread ID: "+ main.getId());
            main.start();
        public void mousePressed(MouseEvent e) {
        public void mouseEntered(MouseEvent e) {
        public void mouseExited(MouseEvent e) {
        public void mouseClicked(MouseEvent e) {
    // appletdemo.java
    import java.applet.*;
    import java.awt.*;
    public class appletdemo extends Applet{
        Board b = new Board();
        public void init() {
            System.out.println("start ");
            setLayout(new BorderLayout());
            this.add(b);
            b.init();
            setVisible(true);
    }

    my evaluation function is complicate, so i don't want to show it here. Instead i showed you a slow for loop for testing. I tried yield() instead of interrupt() in void run(). it does pause the thread, but I can't resume it without using following in mouseReleased()
    main = new Thread(this);
            main.start();it just created a new thread after every human move, that is not i want. I tried main.resume(), it didn't work. How do i wake up the yielded thread? would you please try it out? it runs as follows:
    #1 click on any regin on the applet. ( you play as red, the gui draws a red piece)
    #2 the compute thinks a move (computer plays as blue, you wait a few seconds, the gui draws a blue piece)
    #3 go back to #1

  • Direct Path Read waits are not showing in Elapsed time

    Hi,
    I'm having a question regarding interpretation of a SQL trace file. I'm on Oracle 11.2.0.1 HP/UX 64 bit.
    Following is only the overall result of the trace (it is quite big).
    My question is about the Direct Path Read waits which are totallizing 268s of wait but are not showing in the fetch elapsed time (49.58s) and are not showing anywhere in the trace except in the overall result.
    I do not understand why it is not part of the Elapsed time...
    For info, the trace is for the specific session that was performing all the required queries to display an online report. The database is accessed by the Java application using Hybernate.
    The trace was obtained by the following SQL:
    exec sys.dbms_monitor.serv_mod_act_trace_enable(service_name=>'SYS$USERS',waits=>true,binds=>true);Then I query the sessions to find the one created by the application.
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse       36      0.43       0.51          0          5          0           0
    Execute     62      0.01       0.01          0          0          0           0
    Fetch      579      4.01      49.06       3027     153553          0        5516
    total      677      4.45      49.58       3027     153558          0        5516
    Misses in library cache during parse: 29
    Misses in library cache during execute: 2
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                   32754        0.00          0.03
      SQL*Net message from client                 32753        2.33        232.01
      Disk file operations I/O                      179        0.00          0.02
      db file sequential read                      2979        0.54         45.72
      SQL*Net more data to client                133563        0.04          5.30
      direct path read                            34840        0.94        268.21
      SQL*Net more data from client                1075        0.00          0.02
      db file scattered read                          6        0.03          0.11
      asynch descriptor resize                       52        0.00          0.00
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse       25      0.00       0.02          0          0          0           0
    Execute     58      0.05       0.04          0          0          0           0
    Fetch      126      0.00       0.04          4        161          0         123
    total      209      0.05       0.11          4        161          0         123
    Misses in library cache during parse: 3
    Misses in library cache during execute: 3
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      Disk file operations I/O                        1        0.00          0.00
      db file sequential read                         4        0.01          0.03
      asynch descriptor resize                        1        0.00          0.00
       37  user  SQL statements in session.
       57  internal SQL statements in session.
       94  SQL statements in session.
    Trace file: oxd1ta00_ora_16542.trc
    Trace file compatibility: 11.1.0.7
    Sort options: default
           1  session in tracefile.
          37  user  SQL statements in trace file.
          57  internal SQL statements in trace file.
          94  SQL statements in trace file.
          57  unique SQL statements in trace file.
      241517  lines in trace file.
         568  elapsed seconds in trace file.Thanks
    Christophe

    Christophe Lize wrote:
    Closing this thread even if it's not answered...Sorry, I don't have time to test this myself now, but you shouldn't mark this thread as answered if it is not, because other people might find it and think they find an answer if they have a similar question.
    I suggest you try the following to narrow down things:
    1. Open the RAW trace file and check the cursor numbers of the "direct path reads" - check if you can find any references for those cursor numbers manually. The cursor numbers are those numbers behind the WAIT #<xx>, and you can check if you find any other entry unequal to WAIT #<xx> with the same #<xx>, for example EXEC #<xx> or FETCH #<xx>
    A short primer on how to interpret the raw trace file can also be found in MOS document 39817.1
    2. Run the RAW trace file through alternative free trace file analyzers like SQLDeveloper (yes it can process raw trace files), OraSRP or Christian Antognini's TVD$XTAT. If you have My Oracle Support access you can also try Oracle's own extended Trace Analyzer (TRCA / TRCANLZR). See MOS Note 224270.1
    Check if these tools tell you more about your specific wait event and oddities with the trace file in general.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    Co-author of the "OakTable Expert Oracle Practices" book:
    http://www.apress.com/book/view/1430226684
    http://www.amazon.com/Expert-Oracle-Practices-Database-Administration/dp/1430226684

  • Help with quit function and elapsed time function.

    I have this annoying assignment game here and I am almost finished with it. I got two problems, the first is that the quit function partly works it quits from the game but it is giving me a "Guess is to high" message. I've tried so many things but nothing seems to work.
    The other problem is that the elapsed time " *(long f = System.currentTimeMillis()/1000;)* " starts to count before you actually write something for example if you run the program without writing something for 5 minutes, the highscore list will show your time you finished the game + these 5 minutes.
    If somebody could give me a hint or could explain to me how I could fix these problems I would be very thankful.
    import java.util.*;
    class Game  {
         public static void main(String[] arg) {
              int RAN,Entered_number=0,count=0;
              String guess1[] = new String[1];
              int guess2[] = new int[1];
              int time[] = new int[1];
              String NP1[];
              int NP2[];
              int NP3[];
              int j=0;
              Scanner scan=new Scanner(System.in);
              Scanner kb = new Scanner(System.in);
              Random myRandomizer = new Random();
              RAN= Math.abs(myRandomizer.nextInt() % 1000) + 1;
              System.out.println("\t\t\t"+"Hello and welcome to this guessing game!");
              System.out.println("\t\t\t"+"Start guessing, it's a number between 1 and 1000...");
              System.out.print("--------------------------------------------------");
              System.out.println("-----------------------------");
              System.out.println("please enter your number:");
              String control="";//control is just a name for the variable. it's used to read in the whole line if you have written something that is not a number.
              String name="";
              String answer="";
              boolean okgame=true;//is used so that you can play the game as long as the variable okgame is true.
              long f = System.currentTimeMillis()/1000;
              while((Entered_number!=RAN) && okgame)//controls if the number is different then RAN and that okgame is true.
                   System.out.print(RAN);
                   System.out.print(">");
                   if(scan.hasNextInt())//checks in advance that what you have written is a number, if so then it can read it as Entered_number.
                        Entered_number=scan.nextInt();
                   else
                        control=scan.nextLine();//Reads int the whole line to control what has been written in.
                        if(control.equalsIgnoreCase("quit"))//if control is = quit, then compare to will return 0.
                             okgame=false; //if you have written quit okgame, you put in false to quit the game.
                             // Entered_number=0;//initiates entered_number all over again to show message stupid guess i wont count that.
                   if(okgame)//as long as okgame is true it will show the result otherwise you go to else to show that the game is finished.
                        if((Entered_number>RAN)&&(Entered_number>=1)&&(Entered_number<=1000))
                             System.out.println("Guess is too high!");
                             count++;
                        else if((Entered_number<RAN)&&(Entered_number>=1)&&(Entered_number<=1000))
                             System.out.println("Guess is too low!");
                             count++;
                        else if((Entered_number>1000)||(Entered_number<1))
                             System.out.println("Stupid guess! I won't count that...");
                        else if (Entered_number==RAN)
                             long p = System.currentTimeMillis()/1000;
                             count++;
                             System.out.println("****Guess is CORRECT!");
                             System.out.print("****You guessed it in"+" "+count+" guesses and ");
                             System.out.print(p - f);
                             System.out.println(" seconds.");
                             System.out.println("please enter your name:");
                             System.out.print(">");
                             name=kb.next();
                             System.out.println("Do you want to play again ?(y/n)"); 
                             System.out.print(">");
                             answer=kb.next();
                             if(answer.equalsIgnoreCase("n"))
                                  System.out.println("**** The game is over.");
                                  okgame=false;
                             if(answer.equalsIgnoreCase("y"))
                                  Random myRandom = new Random();
                                  RAN = Math.abs(myRandom.nextInt() % 1000) + 1;
                                  System.out.println("current high score list:");
                                  long ttime = p-f;
                                  int ta = (int)ttime;
                                  j++;
                                  if (j > 1){
                                       NP1 = new String[j];
                                       NP2 = new int[j];
                                       NP3 = new int[j];
                                       for (int n = 1; n < j; n++){
                                            NP1[n-1] = guess1[n-1];
                                            NP2[n-1] = guess2[n-1];
                                            NP3[n-1] = time[n-1];
                                       NP1[j-1] = name;
                                       NP2[j-1] = count;
                                       NP3[j-1] = ta;
                                       guess1 = new String[j];
                                       guess1 = NP1;
                                       time = new int[j];
                                       guess2 = new int[j];
                                       guess2 = NP2; 
                                       time = NP3;
                                       for (int w = 1; w < guess2.length; w++) {
                                            for (int x = 1; x < guess2.length; x++) {
                                                 if (guess2[x] < guess2[x-1]) {
                                                      int z4, z5,z6,z7;
                                                      String z2, z3;
                                                      z4 = guess2[x];
                                                      z5 = guess2[x-1];
                                                      guess2[x] = z5;
                                                      guess2[x-1] = z4;
                                                      z2 = guess1[x];
                                                      z3 = guess1[x-1];
                                                      guess1[x] = z3;
                                                      guess1[x-1] = z2;
                                                      z6 = time[x];
                                                      z7 = time[x-1];
                                                      time[x] = z7;
                                                      time[x-1] = z6;
                                       for (int al = 1; al < time.length; al++) {
                                            for (int o = 1; o < time.length; o++) {
                                                 if (guess2[o] == guess2[o-1]) {
                                                      if (time[o] < time[o-1]) {
                                                           int z4, z5, z6 ,z7;
                                                           String z2, z3;
                                                           z2 = guess1[o]; z3 = guess1[o-1];
                                                           z4 = guess2[o]; z5 = guess2[o-1];
                                                           z6 = time[o]; z7 = time[o-1];
                                                           guess1[o] = z3; guess1[o-1] = z2;
                                                           guess2[o] = z5; guess2[o-1] = z4;
                                                           time[o] = z7; time[o-1] = z6;
                                  else {
                                       guess1[j-1] = name;
                                       guess2[j-1] = count;
                                       time[j-1] = ta;
                                  System.out.println("Number\t\tName\t\tHigh Score\tTime (Seconds)");
                                  System.out.println("------\t\t----\t\t----------\t--------------");
                                  for (int h = 0; h < j; h++) {
                                       System.out.println(" " + (h+1) + "\t\t" + guess1[h] + "\t\t" + guess2[h] + "\t\t" + time[h]);
                                  System.out.println("");
                                  System.out.println("Start guessing, it's a number between 1 and 1000...");
                             count=0;
    //-----------------------------------------------------------------------------------------------------------------------------------------------------PS I'm not done with the comments yet so that could be a little confusing for you guys =P
    Thanks!
    /chill

    else {
                                       guess1[j-1] = name;
                                       guess2[j-1] = count;
                                       time[j-1] = ta;
                                  System.out.println("Number\t\tName\t\tHigh Score\tTime (Seconds)");
                                  System.out.println("------\t\t----\t\t----------\t--------------");
                                  for (int h = 0; h < j; h++) {
                                       System.out.println(" " + (h+1) + "\t\t" + guess1[h] + "\t\t" + guess2[h] + "\t\t" + time[h]);
                                  System.out.println("");
                                  System.out.println("Start guessing, it's a number between 1 and 1000...");
                                                                                               f=System.currentTimeMillis()/1000;////////////include this line here
                             count=0;
                   }

  • Calculating Elapsed Time Is Off By One Hour

    I am fully aware of many topics discussed in the various forums here related to the OS timezone and DST settings impacting how the JVM will process date/time calculations. I am running on Windows XP Professional, and I have checked and double checked the timezone setting, it is correctly set to Central Time and the "Automatically adjust clock for daylight saving changes" checkbox is checked.
    The code found at the end of this message clearly shows the problem for which I have yet to find an explination. I intended to be able to use a timer to update a string to show how much time has elapsed since the start of anything for which I need to know this information. As you can see by the results (example of which is listed after the code), the timezone and DST offsets seem to be properly retrieved by the JVM, but if this is the case, then why is the elapsed time value off by one hour?
    I am looking for a solution/explanation involving the date/time classes, not a workaround whereby I end up extracting multiple time representation subsets and manipulating them myself. Any help will be greatly appreciated.
    * TestTimeZone.java
    * Created on September 12, 2004, 7:18 PM
    import java.io.*;
    import java.util.*;
    import java.awt.event.*;
    import java.sql.*;
    import java.text.*;
    * @author  Jared
    public class TestTimeZone {
        java.util.Date startDt;
        /** Creates a new instance of TestTimeZone */
        public TestTimeZone() {
         * @param args the command line arguments
        public static void main(String[] args) {
            new TestTimeZone().go();
        private void go() {
            startDt = new java.util.Date();
            TimeZone tz = TimeZone.getDefault();
            System.out.println("the default timezone is " + tz.getDisplayName(true, TimeZone.LONG));
            System.out.println("the default timezone ID is " + tz.getID());
            System.out.println("useDaylightTime = " + tz.useDaylightTime());
            System.out.println("default locale = " + Locale.getDefault().toString());
            javax.swing.Timer t = new javax.swing.Timer(1000, new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    java.util.Date currDt = new java.util.Date();
                    Calendar cal = Calendar.getInstance();
                    long elapsedTime = currDt.getTime() - startDt.getTime() -
                        (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET));
                    SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
                    System.out.println("Elapsed: " + formatter.format(new java.util.Date(elapsedTime)) +
                        " Start: " + formatter.format(startDt) +
                        " Current: " + formatter.format(currDt));
            t.start();
            while (true) try {
                Thread.sleep(10);
            } catch (Exception e) {
                e.printStackTrace();
    }And here is the result I am seeing:
    the default timezone is Central Daylight Time
    the default timezone ID is America/Chicago
    useDaylightTime = true
    default locale = en_US
    Elapsed: 23:00:01 Start: 00:03:57 Current: 00:03:58
    Elapsed: 23:00:02 Start: 00:03:57 Current: 00:03:59
    Elapsed: 23:00:03 Start: 00:03:57 Current: 00:04:00
    Elapsed: 23:00:04 Start: 00:03:57 Current: 00:04:01
    Elapsed: 23:00:05 Start: 00:03:57 Current: 00:04:02
    "

    Great. Now that we have gotten half way to the goal, please let me know how you intend to get that difference in miliseconds presented as a time value using any of the date/time classes Java has to offer. That way, I don't have to rewrite the code that puts it into a properly formatted String (the kind folks at Sun have already written that code). Using date/time classes to acheive this is what I attempted with my application. I added the milisecond adjustments for TZ and DST because if I didn't the reported elapsed time would be off by 6 hours, not just 1.
    I am open to all suggestions.

Maybe you are looking for