steveohara / j2mod

Enhanced Modbus library implemented in the Java programming language
Apache License 2.0
275 stars 110 forks source link

switched to scheduled executor service instead of timer #115

Closed mkurt closed 3 years ago

mkurt commented 3 years ago

Hi @steveohara and @akochubey2004,

First of all thanks for your efforts. I find useful to being able to detect connection time idle timeouts which is referenced at #108. Currently we are using system.nanotime to detect idle time duration and i think it's correct. The thing is watchdog is based on Timer class so it is using System.currentTimeMillis. Timer class is sensitive to system time changes so i suggest a little change to use single threaded scheduled executor service. Scheduled executor service uses system.nanotime internally and i think the code will be more resilient when system time back shifts.

Please look at https://stackoverflow.com/questions/18803695/how-is-the-timer-class-in-java-sensitive-to-the-system-clock

steveohara commented 3 years ago

Merged and built into the latest 3.0.0 SNAPSHOT