Is there a way for a Java program to detect when the operating system is about to fall asleep, or if it fails, at least detects an awakening?
The real problem is that in a particular application in the background, several operations are performed with the MySQL database. When testing on a Windows machine, these database transactions are interrupted after a sleep / wake cycle, which causes a lot of errors in the program. These errors usually look something like this:
java.net.SocketException
MESSAGE: Software caused connection abort: recv failed
If we could respond to the โwill sleep soonโ event, we can try to suspend background operations, surpassing the problem. Less than ideal, if we could respond to the โjust wake upโ event, we could at least suppress error messages.
java mysql sleep database-connection
Alexander Ljungberg
source share