title: How to detect a long gc from within a JVM?
body: <p>How can I detect a GC (<strong>Edit</strong> or any stall)  which exceeds some configured app timeout so that I can log a warning (or dynamically extend the timeout)?</p>
  
  <p><strong>Edit</strong> I am not asking for alternatives or workarounds like monitoring. I am writing a library and I cannot control the environment or settings. Whilst I will clearly document that users of the library must set an appropriate timeout I still expect people to overlook that else change jvm heap settings years later and forget to increase the timeouts. Support will be simpler if I can warn in the library logging of a possible pause greater than the configured timeouts. It doesn't have to be perfect detection "good enough" would reduce time wasted on library users not setting a sensible timeout.</p>
  
  <p><strong>Edit</strong> and to be clear the library works fine even if there is a big GC yet there is a good reason to have well chosen timeout which is to detect a crash such that the library tries to connect to an alternate peer. </p>