Understanding the output of println("${Thread.currentThread()}")

Viewed 413

When I print a coroutine thread out

println("${Thread.currentThread()}")

It will show

Thread[DefaultDispatcher-worker-1 @coroutine#4,5,main]

I know that

  • DefaultDispatcher-worker-1 is the Thread currently running in
  • @coroutine#4 is the coroutine name
  • 5 is the priority of the thread it is running in
  • main -- what is this referring to? the launching thread?

I don't understand what main is for, although I know that refers to the main thread.

Is it the parent thread? (I doubt so, as I try using a non-main parent thread, it still show main)
Is it the launching thread?
If not, what is it?

1 Answers

By checking the toString() function of the Thread, found that

    public String toString() {
        ThreadGroup group = getThreadGroup();
        if (group != null) {
            return "Thread[" + getName() + "," + getPriority() + "," +
                           group.getName() + "]";
        } else {
            return "Thread[" + getName() + "," + getPriority() + "," +
                            "" + "]";
        }
    }

Looks like it is the thread group name.

Related