How Java VisualVM shows threads that are not running/finished?












0














enter image description here



For testing I've created a thread which has just sleep in it. And I know that GC doesnt collect them for a while even if their usage is done but when you dont keep them as an object after they complete their task they should've be gone.



So for testing purposes I used Java VisualVM but this is the first time I'm using it. And I see all these timer threads lying around with 0ms but I can still see them. Is this normal? And what does this mean? If I spam thousands of them, will it slow down my app?










share|improve this question






















  • If the thread disappears from the list as soon as it ends, you won't have time to analyze the result, now would you? So when the app is monitored, the threads live on, for your debugging pleasure.
    – Andreas
    Nov 13 '18 at 6:27










  • So those white colored boxes of threads will not appear when I run the app?
    – Samed Sivaslıoğlu
    Nov 13 '18 at 6:29










  • Try stopping and restarting VisualVM
    – Andreas
    Nov 13 '18 at 6:29










  • @Andreas Basically what I'm asking is will this code "new Thread(task).start()" cause any problems for me? Because it'll be done massively
    – Samed Sivaslıoğlu
    Nov 13 '18 at 6:30








  • 2




    These are two different questions. As Andreas said, these threads are not active anymore, so likely not consuming any resources (whether they do is not recognizable in that view). But that doesn’t mean that new Thread(task).start() is a recommended coding style. If you do this “massively” you are wasting resources. You should use a thread pool with a maximum thread limit, to allow reusing the threads. Try Executors.newFixedThreadPool(number) or newCachedThreadPool()
    – Holger
    Nov 13 '18 at 9:28


















0














enter image description here



For testing I've created a thread which has just sleep in it. And I know that GC doesnt collect them for a while even if their usage is done but when you dont keep them as an object after they complete their task they should've be gone.



So for testing purposes I used Java VisualVM but this is the first time I'm using it. And I see all these timer threads lying around with 0ms but I can still see them. Is this normal? And what does this mean? If I spam thousands of them, will it slow down my app?










share|improve this question






















  • If the thread disappears from the list as soon as it ends, you won't have time to analyze the result, now would you? So when the app is monitored, the threads live on, for your debugging pleasure.
    – Andreas
    Nov 13 '18 at 6:27










  • So those white colored boxes of threads will not appear when I run the app?
    – Samed Sivaslıoğlu
    Nov 13 '18 at 6:29










  • Try stopping and restarting VisualVM
    – Andreas
    Nov 13 '18 at 6:29










  • @Andreas Basically what I'm asking is will this code "new Thread(task).start()" cause any problems for me? Because it'll be done massively
    – Samed Sivaslıoğlu
    Nov 13 '18 at 6:30








  • 2




    These are two different questions. As Andreas said, these threads are not active anymore, so likely not consuming any resources (whether they do is not recognizable in that view). But that doesn’t mean that new Thread(task).start() is a recommended coding style. If you do this “massively” you are wasting resources. You should use a thread pool with a maximum thread limit, to allow reusing the threads. Try Executors.newFixedThreadPool(number) or newCachedThreadPool()
    – Holger
    Nov 13 '18 at 9:28
















0












0








0







enter image description here



For testing I've created a thread which has just sleep in it. And I know that GC doesnt collect them for a while even if their usage is done but when you dont keep them as an object after they complete their task they should've be gone.



So for testing purposes I used Java VisualVM but this is the first time I'm using it. And I see all these timer threads lying around with 0ms but I can still see them. Is this normal? And what does this mean? If I spam thousands of them, will it slow down my app?










share|improve this question













enter image description here



For testing I've created a thread which has just sleep in it. And I know that GC doesnt collect them for a while even if their usage is done but when you dont keep them as an object after they complete their task they should've be gone.



So for testing purposes I used Java VisualVM but this is the first time I'm using it. And I see all these timer threads lying around with 0ms but I can still see them. Is this normal? And what does this mean? If I spam thousands of them, will it slow down my app?







java multithreading jvm visualvm jvisualvm






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 6:23









Samed Sivaslıoğlu

15915




15915












  • If the thread disappears from the list as soon as it ends, you won't have time to analyze the result, now would you? So when the app is monitored, the threads live on, for your debugging pleasure.
    – Andreas
    Nov 13 '18 at 6:27










  • So those white colored boxes of threads will not appear when I run the app?
    – Samed Sivaslıoğlu
    Nov 13 '18 at 6:29










  • Try stopping and restarting VisualVM
    – Andreas
    Nov 13 '18 at 6:29










  • @Andreas Basically what I'm asking is will this code "new Thread(task).start()" cause any problems for me? Because it'll be done massively
    – Samed Sivaslıoğlu
    Nov 13 '18 at 6:30








  • 2




    These are two different questions. As Andreas said, these threads are not active anymore, so likely not consuming any resources (whether they do is not recognizable in that view). But that doesn’t mean that new Thread(task).start() is a recommended coding style. If you do this “massively” you are wasting resources. You should use a thread pool with a maximum thread limit, to allow reusing the threads. Try Executors.newFixedThreadPool(number) or newCachedThreadPool()
    – Holger
    Nov 13 '18 at 9:28




















  • If the thread disappears from the list as soon as it ends, you won't have time to analyze the result, now would you? So when the app is monitored, the threads live on, for your debugging pleasure.
    – Andreas
    Nov 13 '18 at 6:27










  • So those white colored boxes of threads will not appear when I run the app?
    – Samed Sivaslıoğlu
    Nov 13 '18 at 6:29










  • Try stopping and restarting VisualVM
    – Andreas
    Nov 13 '18 at 6:29










  • @Andreas Basically what I'm asking is will this code "new Thread(task).start()" cause any problems for me? Because it'll be done massively
    – Samed Sivaslıoğlu
    Nov 13 '18 at 6:30








  • 2




    These are two different questions. As Andreas said, these threads are not active anymore, so likely not consuming any resources (whether they do is not recognizable in that view). But that doesn’t mean that new Thread(task).start() is a recommended coding style. If you do this “massively” you are wasting resources. You should use a thread pool with a maximum thread limit, to allow reusing the threads. Try Executors.newFixedThreadPool(number) or newCachedThreadPool()
    – Holger
    Nov 13 '18 at 9:28


















If the thread disappears from the list as soon as it ends, you won't have time to analyze the result, now would you? So when the app is monitored, the threads live on, for your debugging pleasure.
– Andreas
Nov 13 '18 at 6:27




If the thread disappears from the list as soon as it ends, you won't have time to analyze the result, now would you? So when the app is monitored, the threads live on, for your debugging pleasure.
– Andreas
Nov 13 '18 at 6:27












So those white colored boxes of threads will not appear when I run the app?
– Samed Sivaslıoğlu
Nov 13 '18 at 6:29




So those white colored boxes of threads will not appear when I run the app?
– Samed Sivaslıoğlu
Nov 13 '18 at 6:29












Try stopping and restarting VisualVM
– Andreas
Nov 13 '18 at 6:29




Try stopping and restarting VisualVM
– Andreas
Nov 13 '18 at 6:29












@Andreas Basically what I'm asking is will this code "new Thread(task).start()" cause any problems for me? Because it'll be done massively
– Samed Sivaslıoğlu
Nov 13 '18 at 6:30






@Andreas Basically what I'm asking is will this code "new Thread(task).start()" cause any problems for me? Because it'll be done massively
– Samed Sivaslıoğlu
Nov 13 '18 at 6:30






2




2




These are two different questions. As Andreas said, these threads are not active anymore, so likely not consuming any resources (whether they do is not recognizable in that view). But that doesn’t mean that new Thread(task).start() is a recommended coding style. If you do this “massively” you are wasting resources. You should use a thread pool with a maximum thread limit, to allow reusing the threads. Try Executors.newFixedThreadPool(number) or newCachedThreadPool()
– Holger
Nov 13 '18 at 9:28






These are two different questions. As Andreas said, these threads are not active anymore, so likely not consuming any resources (whether they do is not recognizable in that view). But that doesn’t mean that new Thread(task).start() is a recommended coding style. If you do this “massively” you are wasting resources. You should use a thread pool with a maximum thread limit, to allow reusing the threads. Try Executors.newFixedThreadPool(number) or newCachedThreadPool()
– Holger
Nov 13 '18 at 9:28














2 Answers
2






active

oldest

votes


















-1














Once VisualVM connects to the running JVM, it will keep references to all started threads, so those Thread objects are not garbage collected when the threads stop running.



They are retained by VisualVM so you can still see the statistics collected for them.



The Thread objects will become unreachable and GC'able once you exit VisualVM, so stopping and restarting VisualVM will "clear" the list of ended threads.






share|improve this answer





















  • I can assure you that VisualVM does not keep references to all started threads.
    – Tomas Hurka
    Nov 19 '18 at 7:36





















0














You see all that Thread- threads, because by default VisualVM will show you all the threads (including those, which were finished during monitoring session). To see just Live threads, switch View combo from All threads to Live threads. VisualVM does not keep references to all started threads, they can be garbage-collected just fine.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274982%2fhow-java-visualvm-shows-threads-that-are-not-running-finished%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    -1














    Once VisualVM connects to the running JVM, it will keep references to all started threads, so those Thread objects are not garbage collected when the threads stop running.



    They are retained by VisualVM so you can still see the statistics collected for them.



    The Thread objects will become unreachable and GC'able once you exit VisualVM, so stopping and restarting VisualVM will "clear" the list of ended threads.






    share|improve this answer





















    • I can assure you that VisualVM does not keep references to all started threads.
      – Tomas Hurka
      Nov 19 '18 at 7:36


















    -1














    Once VisualVM connects to the running JVM, it will keep references to all started threads, so those Thread objects are not garbage collected when the threads stop running.



    They are retained by VisualVM so you can still see the statistics collected for them.



    The Thread objects will become unreachable and GC'able once you exit VisualVM, so stopping and restarting VisualVM will "clear" the list of ended threads.






    share|improve this answer





















    • I can assure you that VisualVM does not keep references to all started threads.
      – Tomas Hurka
      Nov 19 '18 at 7:36
















    -1












    -1








    -1






    Once VisualVM connects to the running JVM, it will keep references to all started threads, so those Thread objects are not garbage collected when the threads stop running.



    They are retained by VisualVM so you can still see the statistics collected for them.



    The Thread objects will become unreachable and GC'able once you exit VisualVM, so stopping and restarting VisualVM will "clear" the list of ended threads.






    share|improve this answer












    Once VisualVM connects to the running JVM, it will keep references to all started threads, so those Thread objects are not garbage collected when the threads stop running.



    They are retained by VisualVM so you can still see the statistics collected for them.



    The Thread objects will become unreachable and GC'able once you exit VisualVM, so stopping and restarting VisualVM will "clear" the list of ended threads.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 13 '18 at 21:33









    Andreas

    75.4k460122




    75.4k460122












    • I can assure you that VisualVM does not keep references to all started threads.
      – Tomas Hurka
      Nov 19 '18 at 7:36




















    • I can assure you that VisualVM does not keep references to all started threads.
      – Tomas Hurka
      Nov 19 '18 at 7:36


















    I can assure you that VisualVM does not keep references to all started threads.
    – Tomas Hurka
    Nov 19 '18 at 7:36






    I can assure you that VisualVM does not keep references to all started threads.
    – Tomas Hurka
    Nov 19 '18 at 7:36















    0














    You see all that Thread- threads, because by default VisualVM will show you all the threads (including those, which were finished during monitoring session). To see just Live threads, switch View combo from All threads to Live threads. VisualVM does not keep references to all started threads, they can be garbage-collected just fine.






    share|improve this answer


























      0














      You see all that Thread- threads, because by default VisualVM will show you all the threads (including those, which were finished during monitoring session). To see just Live threads, switch View combo from All threads to Live threads. VisualVM does not keep references to all started threads, they can be garbage-collected just fine.






      share|improve this answer
























        0












        0








        0






        You see all that Thread- threads, because by default VisualVM will show you all the threads (including those, which were finished during monitoring session). To see just Live threads, switch View combo from All threads to Live threads. VisualVM does not keep references to all started threads, they can be garbage-collected just fine.






        share|improve this answer












        You see all that Thread- threads, because by default VisualVM will show you all the threads (including those, which were finished during monitoring session). To see just Live threads, switch View combo from All threads to Live threads. VisualVM does not keep references to all started threads, they can be garbage-collected just fine.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 '18 at 7:35









        Tomas Hurka

        5,0371828




        5,0371828






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274982%2fhow-java-visualvm-shows-threads-that-are-not-running-finished%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine