I work with threads in my project. Among other threads, two HandlerThread created in two different classes in this way:

 HandlerThread thread = new HandlerThread("ServiceThread", Process.THREAD_PRIORITY_DEFAULT); 

Then they start: thread.start(); and i use their loops.
And just now I discovered that they are created with exactly the same name (the first parameter in the constructor is the name).
My question is, can there be problems due to the fact that the threads have the same name? Are the names any identifiers for the streams?

    3 answers 3

    There will be no problems.

    When creating a new HandlerThread , the constructor is called:

      public HandlerThread(String name, int priority) { super(name); mPriority = priority; } 

    We go deep into and see

      if (threadName == null) { this.name = "Thread-" + id; } else { this.name = threadName } 

    What is the practical confirmation written in Javadoc :

    Each thread has a name for identification purposes. More than one thread can have the same name. If the name is not specified when the stream is created, a new name is generated for it.

      No, names in thread have no meaning except the convenience of testing and logging. The thread unique identifier will be pid .

        From offdock

        Every thread has a name for identification purposes. More than one thread may have the same name. If a thread is not specified, it is generated for it.

        The idea of ​​the problem does not say anything, then it is normal