1

When I log the two below thread Ids, they are different.

long threadId = Thread.currentThread().getId();
long threadId2 = android.os.Process.myTid();

But from Android document, they are quite the same:

/**
* Returns the Thread of the caller, that is, the current Thread.
*/
public static native Thread currentThread();

So I assume the first line will returns the id of the caller thread.

then this

/**
     * Returns the identifier of the calling thread, which be used with
     * {@link #setThreadPriority(int, int)}.
     */
    public static final int myTid() {
        return Os.gettid();
    }

From the comment, it looks like it is also the id of the caller thread (although they use the word 'calling').

They are supposed the same, or am I missing anything? Thanks.

EyeQ Tech
  • 7,198
  • 18
  • 72
  • 126

2 Answers2

0

ThreadId and Tid are different.

ThreadId is more like pid, while Tid is a bit more complicated.

[Correction:] ThreadId is not pid, it's actually the value of ++Thread.count

See details here: Difference between pid and tid and here: The difference between Thread.currentThread().getId() and Process.myTid() in Android

Community
  • 1
  • 1
Mine
  • 4,123
  • 1
  • 25
  • 46
  • Tks for your answer, but in my question above, which var is Tid? Second? – EyeQ Tech Feb 12 '15 at 07:17
  • Yes, `myTid()` returns Tid – Mine Feb 12 '15 at 07:22
  • Actually there is a more accurate answer here: http://stackoverflow.com/questions/19898321/the-difference-between-thread-currentthread-getid-and-process-mytid-in-and. I'll update my answer because `getId()` is not a *real* pid. – Mine Feb 12 '15 at 07:27
0

Thread.currentThread().getId() : Returns the identifier of the caller thread , that is, the current Thread. android.os.Process.myTid(): Returns the identifier of the calling thread, which be used with setThreadPriority(int, int). Here Set the priority of a thread, based on Linux priorities.

Parameters tid The identifier of the thread/process to change. priority A Linux priority level, from -20 for highest scheduling priority to 19 for lowest scheduling priority.

For further reference

http://developer.android.com/reference/android/os/Process.html#myTid()

amar
  • 137
  • 2
  • 12