0

I am trying to learn about heapdumps and threaddumps and in doing that created a very simple application which is using completable future :

public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 40; i++) {
            CompletableFuture.runAsync(() -> {
                System.out.println(Thread.currentThread().getName());
               // service.perform();
            }).join();

    }
}

I have also added a system property "-Djava.util.concurrent.ForkJoinPool.common.parallelism=1" so that it will create thread per task and it is doing that, but when monitoring it through visualvm i am not able to see these threads :

Total threads in visualvm

All threads Info

How to know the lifecycle of those threads created by forkjoinpool ? and how to see all threads info.?

Akash tiwari
  • 213
  • 1
  • 10

1 Answers1

0

How to know the lifecycle of those threads created by forkjoinpool ? and how to see all threads info.?

I'm not 100% sure what information you are looking for. In general the more you try to instrument your thread code the less performant it is going to be. That said, you could add a Thread.currentThread().getId() to your system out to show what threads are being used in your jobs.

You could also create your own ForkJoinPool with your own ThreadFactory which you could show when the threads were started and when they exited but overriding the run() method so that it prints that it is starting, runs the delegate.run(), and then prints that it is stopping.

Gray
  • 115,027
  • 24
  • 293
  • 354