Search code examples
javaspringmaventomcat7

What is meaning of the number after exec in "[http-bio-8080-exec-494] [ERROR]"?


While going through an investigation in a legacy Java Spring Maven project deployed on tomcat 7 the logs stated like below-

2018-08-29 18:16:42:471 +0600 [http-bio-8080-exec-494] [ERROR]

Asking to demystify the number after

exec-

So basically the meaning of "exec"? which is 494 for the above case.


Solution

  • It's most probably the thread id generated by a custom ThreadFactory, just like:

    Executor executor = Executors.newFixedThreadPool(4, new ThreadFactory() {
        AtomicInteger threadId = new AtomicInteger(0);
        @Override
        public Thread newThread(Runnable r) {
            return new Thread(r, "http-bio-8080-exec-" + threadId.getAndIncrement());   // custom a thread factory 
        }
    });
    
    IntStream.range(0, 10).forEach(value -> {
        executor.execute(() -> {    
            System.out.println(Thread.currentThread().getName());   // print thread name
            try {
                Thread.sleep(100);
            } catch (Exception e) {
    
            }
        });
    });
    

    OutPut:

    http-bio-8080-exec-0
    http-bio-8080-exec-1
    http-bio-8080-exec-2
    http-bio-8080-exec-3
    http-bio-8080-exec-0
    http-bio-8080-exec-3
    http-bio-8080-exec-1
    http-bio-8080-exec-2
    http-bio-8080-exec-0
    http-bio-8080-exec-3