5 Replies Latest reply: Oct 20, 2010 10:24 AM by 805490 RSS

    About the TID

    805490
      Hello,

      Assuming that each RealTimeThread is mapped to a one thread kernel on the operating system (e.g. as it happens when I create a thread with pthread_create), I would like to know if the function getId returns the identification kernel of the thread (TID). When I execute the command "ps" the thread's TID seems different of the identifier that I obtain from a Java application. If my suspicious is correct, how can I get the TID from Java?

      Regards,
        • 1. Re: About the TID
          davidholmes
          Thread.getId() simply returns the value of a counter, it is not related to any identifier associated with the native thread.

          I'm not aware of any Java API that will allow you to get the native thread ID directly. If you are on Solaris you could use DTrace to obtain that information.

          David Holmes
          Oracle
          • 2. Re: About the TID
            805490
            Thank you for your answer. I am not using Solaris at this moment. Now, I am wondering if the linux thread id (obtained using "ps" command) and the java thread id (for example, obtained using Thread.getID() in java) are related, i.e. linux thread id = 4001 - java thread id= 1; linux thread id = 4002 - java thread id= 2... and so on.
            • 3. Re: About the TID
              805490
              Answer points still available
              • 4. Re: About the TID
                davidholmes
                802487 wrote:
                Now, I am wondering if the linux thread id (obtained using "ps" command) and the java thread id (for example, obtained using Thread.getID() in java) are related, i.e. linux thread id = 4001 - java thread id= 1; linux thread id = 4002 - java thread id= 2... and so on.
                The Java Thread id is a sequential counter, nothing more, so each new thread gets the next value (including threads created by the libraries).

                There may be a correlation with the Linux TID if Linux assigns thread IDs sequentially as well, but that would assume no other processes or threads on the system are created while the VM is running - which is not likely.

                You would need to introduce native code to get the actual OS thread ID

                David Holmes
                • 5. Re: About the TID
                  805490
                  Thanks. I'll probe it.