giltene / jHiccup

jHiccup is a non-intrusive instrumentation tool that logs and records platform "hiccups" - including the JVM stalls that often happen when Java applications are executed and/or any OS or hardware platform noise that may cause the running application to not be continuously runnable.
Other
677 stars 92 forks source link

Improvement of sleep in loop #35

Open o0lwj0o opened 5 years ago

o0lwj0o commented 5 years ago

Hi, I found an interesting case in this project. It has “Thread.sleep()” in a “while(true)” loop. I found some discussion in Stackoverflow and other website. It can be refactored by using a executor service. https://ejrh.wordpress.com/2012/07/13/sleeping-in-loops-considered-harmful/ https://stackoverflow.com/questions/3535754/netbeans-java-new-hint-thread-sleep-called-in-loop or Maybe use CountDownLatch.await to automatically awake and shutdown.

Detailed websites and lines:

620 | https://github.com/giltene/jHiccup/blob/master/src/main/java/org/jhiccup/HiccupMeter.java

Best regards