4

enter image description here

These Keep-Alive-Timer threads have white label on the left and the white label is not describe its meaning below. I wonder how do these Keep-Alive-Timer threads be created and why.

enter image description here

Actually, I'm using Timer to check heartbeat messages in my program. Whenever a heartbeat comes, I schedule a new TimerTask with a 6 second delay. If there are no heartbeats coming, this TimerTask is triggered and sends an alert.

Andrew Lygin
  • 6,077
  • 1
  • 32
  • 37
bitdancer
  • 1,215
  • 2
  • 19
  • 34

1 Answers1

6

The Keep-Alive-Thread is responsible for maintaining the KeepAliveCache, that stores information about http connections that use the Keep-Alive attribute. If you have at least one such connection, there will be a Keep-Alive-Thread watching them. When you close all keep-alive connections, this thread is destroyed. When you add a new keep-alive connection to the empty cache, JVM starts this thread again.

White color means that the thread is not alive anymore. As you can see, your JVM creates and destroys this thread constantly.

It seems that you are doing the same work manually with your timer tasks that track heartbeats. You close those keep-alive connections after 6 seconds and JVM destroys the Keep-Alive-Thread. You create a new connection and JVM starts a new watching Keep-Alive-Thread.

If you use the Keep-Alive attribute on your http connections, it's better just set the correct timeout and let the JVM do the housekeeping work.

Andrew Lygin
  • 6,077
  • 1
  • 32
  • 37