9

I've written a Java server application that I run on a Debian 7 VServer.

The application itself works just fine, but I notices something very strange.

Issue

After calling java -Xmx200M -jar "CCU.jar I'd expect to see one Java process running my CCU.jar.

When calling top there is just one java process (as expected). But when I call htop I get this:

htop with strange subprocesses

What are all these subprocesses that seem to be the same process (they have the exactly same data showed in the table) but have different PIDs?

hc_dev
  • 8,389
  • 1
  • 26
  • 38
MinecraftShamrock
  • 3,504
  • 2
  • 25
  • 44

2 Answers2

7

A java application is never single threaded (Garbage Collector thread among other). So you always end up with several thread. Moreover, Linux implement thread as Light-weight process therefore, each Java thread will appear as a process with a unique PID in htop.

ortis
  • 2,203
  • 2
  • 15
  • 18
  • Alright. Thanks for the answer. Is this amount of threads strange if my application consists of 3 threads with no clients connected (with the main thread)? – MinecraftShamrock Aug 26 '14 at 10:36
  • Yep, it seems a bit high. Are you using GUI ? – ortis Aug 26 '14 at 10:39
  • No. It's the main thread and one thread to accept incoming TCP connections. But I'm using JDBC with the BoneCP connection pool. That's probably where all the threads come from. – MinecraftShamrock Aug 26 '14 at 10:44
  • So there is the main thread, the client acceptor thread and at least six connection pool threads. Also JDBC uses Log4J wich might spawn threads. Is the thread amount still strange? – MinecraftShamrock Aug 26 '14 at 10:47
  • Nope, seems pretty normal now ;) – ortis Aug 26 '14 at 11:58
  • Thanks :D I just wrote a test application that reads from the command line and outputs it. It uses 13 threads that are spawned by Java. – MinecraftShamrock Aug 26 '14 at 12:03
3

Even the simplest Java application will use several threads for things besides your code. These are for example the garbage collector, finalizer thread and what not.

That many threads indicate that there's some multithreading happening in your application, because Java wouldn't spawn that many just for itself.

Kayaman
  • 72,141
  • 5
  • 83
  • 121