Thread leaking? Is that something we should be concerned about?

Hi,

a collegue of mine saw (in VisualVM), that Smack (3.3.1) creates a lot of threads, when creating a connection, login and disconnecting often.

Attached is a screenshot of the “Threads” tab in VisualVM. As you can see on the scrollbar, it is full of Smack threads.

I am not sure, if this is a problem, but since we have problems with memory leaks and JVM crashes recently, we are also considering this.

Might be related to this question http://community.igniterealtime.org/thread/45332

Any comments on this?

You should be concerened about leaking resources if you don’t want to waste resources. :stuck_out_tongue:

But really, I recommend using Smack 3.4.1.

Other then that, the picture shows a bunch of Smack threads. Based on that information it’s even not clear if it’s a memory leak or just a bunch of Connections. What would be interesting to know is the reason those are not gc’ed, i.e. their path to the gc roots.

Even better would be if you would try the latest version of Smack 4.0. I am planing to release a rc1 of Smack 4.0 in about two weeks. Smack 4.0 includes further fixes regarding memory-leaks that didn’t went into 3.4.1 and a bunch of security fixes.

Resource leaking? I am closing the connection correctly, if you mean that:

Connection connection = new XMPPConnection("…");

try {

connection.connect();

connection.login(“xxx”, “xxx”);

} catch (XMPPException e) {

e.printStackTrace();

} finally {

connection.disconnect();

}

The strange thing is, that the thread dump generated by VisualVM looks fine (only 2-3 Smack threads there) and the heap dump looks fine as well (not that many java.lang.Thread instances there).

Nonetheless, it looks strange. That’s why I wanted to ask, if it is something to be concerned about or just a display quirk in VisualVM.

I will try it with 3.4.1, too.

Resource leaking? I am closing the connection correctly, if you mean that:
Oh, I didn’t want to imply that you did something wrong. Just wanted to play with the question “Thread leaking.Should I be concerned?” You should be concerned if you are concerned about resources.

It seems that the output from our VisualVM is somehow confusing. It says

Live Threads 14

Deamon Threads 12

in the top left corner, but the list below shows far more then 26 threads.

Live threads should include the daemon threads, so it seems that terminated threads are also displayed.

just a sanity check… i know JProfiler does, maybe visualvm does as well — it shows both alive and dead threads by default and you must choose a filter to see only “alive” threads. Perhaps you’re looking at a, history of smack threads during your program’s runtime?

oh, didn’t notice LG’s response lol, ya, what he said!