How Java VisualVM shows threads that are not running/finished?
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
|
show 1 more comment
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
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 thatnew 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. TryExecutors.newFixedThreadPool(number)
ornewCachedThreadPool()
– Holger
Nov 13 '18 at 9:28
|
show 1 more comment
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
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
java multithreading jvm visualvm jvisualvm
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 thatnew 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. TryExecutors.newFixedThreadPool(number)
ornewCachedThreadPool()
– Holger
Nov 13 '18 at 9:28
|
show 1 more comment
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 thatnew 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. TryExecutors.newFixedThreadPool(number)
ornewCachedThreadPool()
– 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
|
show 1 more comment
2 Answers
2
active
oldest
votes
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.
I can assure you that VisualVM does not keep references to all started threads.
– Tomas Hurka
Nov 19 '18 at 7:36
add a comment |
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
I can assure you that VisualVM does not keep references to all started threads.
– Tomas Hurka
Nov 19 '18 at 7:36
add a comment |
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.
I can assure you that VisualVM does not keep references to all started threads.
– Tomas Hurka
Nov 19 '18 at 7:36
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 19 '18 at 7:35
Tomas Hurka
5,0371828
5,0371828
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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. TryExecutors.newFixedThreadPool(number)
ornewCachedThreadPool()
– Holger
Nov 13 '18 at 9:28