As others have pointed out, this is just an incrementing counter.
The reason your log file does not print your thread names in order is because java does not guarantee the execution order of running threads .
If you want to force an order, you need to make the threads wait for each other. A possible way to do this is using a CountDownLatch .
private static CountDownLatch latch; public static void main(String[] args) throws InterruptedException { Thread t1 = new Thread(new Fabric()); Thread t2 = new Thread(new Fabric()); Thread t3 = new Thread(new Fabric());
On the other hand, some classes use ThreadFactory to assign thread names. (e.g. a ScheduledThreadPoolExecutor ). For example, DefaultThreadFactory creates its thread names as follows:
String namePrefix = "pool-" + poolNumber.getAndIncrement() + "-thread-"; String threadName = namePrefix + threadNumber.getAndIncrement()
source share