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

(thread) API-access to stack traces for all threads in an application

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 1.4.2
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_2000

      Description



      Name: rmT116609 Date: 04/15/2004


      A DESCRIPTION OF THE REQUEST :
      It is not possible to dump stack traces for each thread in an application programmatically via an API. A call to Thread.dumpStack() only prints the stack for the currently active thread, but not for any other thread.

      JUSTIFICATION :
      In certain cases, it may be necessary to access stack trace information of all threads in the application. E.g., if one wants to find out the main class (the class with a main method) which started the current application.

      If working in a single-threaded application, this is not a problem (you can throw a dummy-exception, catch this exception, and access the stack trace by using the new StackTraceElement class as of J2SDK 1.4)
      But, if one is working in a multithreaded application, the method above described doesn't work, because the root of the stack trace will be "java.lang.Thread.run()".

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      It would be best, if one could access stack trace information of any thread by calling e.g. Thread.getStackTrace() which operates on any thread (not just the currently active thread) and which returns an array of StackTraceElements (just as Throwable.getStackTrace() in J2SDK 1.4 does).
      ACTUAL -
      Currently, Thread.dumpStack() prints the stack trace of the only currently active thread to System.err. There is no possibility to access information of any other thread. Further, it is not possible to access the stack trace information by using the StackTraceElement class.

      CUSTOMER SUBMITTED WORKAROUND :
      There is no workaround for the case of a multithreaded application, i.e. it is not possible to find out the main class of the currently running application by stepping through the stack trace information.
      (Incident Review ID: 227771)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              psoper Pete Soper (Inactive)
              Reporter:
              rmandalasunw Ranjith Mandala (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: