Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4929401

ThreadMBean.getThreadCpuTime() throws unexpected IllegalArgumentException

    XMLWordPrintable

    Details

    • Subcomponent:
      svc
    • Resolved In Build:
      b25
    • CPU:
      generic
    • OS:
      generic

      Description



      Name: viR10068 Date: 09/28/2003


      The description for the methods ThreadMBean.getThreadCpuTime(long id) says:
      " If the thread of the specified ID is not alive or does not exist,
      this method returns -1."
      But jdk1.5.0-b21 throws the IllegalArgumentException in these cases.

      Note, the jdk1.5.0-b20 returns -1 so it is may be a side effect of the
      bug 4911671 integration.

      Source code:
      =========================== getTMB12.java ====================================
      mport java.io.PrintStream;
      import java.lang.management.*;

      public class getTMB12 {

          public static int run(String argv[], PrintStream out) {
              ThreadMBean c = ManagementFactory.getThreadMBean();
              Thread trd1 = new Thread(), trd2 = new Thread(), trd3 = new Thread();
              long [] idArr = {trd1.getId(), trd2.getId(), trd3.getId()};
       
              try {
                  trd3.setDaemon(!trd3.isDaemon());
                  trd2.start(); trd3.start();
                  trd2.join(); trd3.join();
              } catch (InterruptedException ie) {
                  out.println("Unexpected exception" + ie);
                  return 1;
              }
              try {
                  if (!c.isThreadCpuTimeEnabled()) {
                      c.setThreadCpuTimeEnabled(true);
                  }
                  for (int i = 0; i < idArr.length; i++) {
                      out.println("info for thread ID " + idArr[i]);
                      if (c.getThreadCpuTime(idArr[i]) != -1) {
                          out.println("incorrect thread's CPU time for ID = " + idArr[i]);
                          return 1;
                      }
                  }
              } catch (UnsupportedOperationException ue) {
                  out.println("Passed with UnsupportedOperationException");
              }
              out.println("OKAY");
              return 0;
          }

          public static void main(String argv[]) {
              System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
          }
      }
      =======================================================================
      Execution log:
      % javac getTMB12.java && jdk1.5.0-b21/solaris-sparc/bin/java -showversion getTMB12
      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b21)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b21, mixed mode)

      info for thread ID 7
      Exception in thread "main" java.lang.IllegalArgumentException: Invalid thread ID
              at sun.management.ThreadImpl.getThreadCpuTime0(Native Method)
              at sun.management.ThreadImpl.getThreadCpuTime(ThreadImpl.java:209)
              at getTMB12.run(getTMB12.java:27)
              at getTMB12.main(getTMB12.java:40)
      %


      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mchung Mandy Chung
              Reporter:
              vivsunw Viv Viv (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: