multithreading - How is default new thread name given in java? -


when run program

public class fabric extends thread {     public static void main(string[] args) {         thread t1 = new thread(new fabric());         thread t2 = new thread(new fabric());         thread t3 = new thread(new fabric());         t1.start();         t2.start();         t3.start();     }     public void run() {         for(int = 0; < 2; i++)         system.out.print(thread.currentthread().getname() + " ");     } } 

i output

thread-1 thread-5 thread-5 thread-3 thread-1 thread-3 

is there specific reason why threads given names odd numbers - 1, 3, 5... or unpredictable?

new thread(new fabric()); 

since fabric thread, created 2 threads here :)

jdk8 code:

/* autonumbering anonymous threads. */ private static int threadinitnumber; private static synchronized int nextthreadnum() {     return threadinitnumber++; } 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -