Closed hedgecrw closed 2 years ago
the problem remains, a little later describe in detail what is happening.
@hedgecrw There are no problems with delays, the problem is in the incorrect completion of the work at killall -2 java
jSerialComm-2.9.1-beta2 - I lose the opportunity to work with the port. But I need to send and get a few bytes for the correct completion of work, after which I myself closes the port, call closePort()
jSerialComm:2.7.0 - allowed to read and write bytes, and after calling closePort()
- closed
@sprut666666, the behavior you are describing/relying on in v2.7.0 is actually undefined, incorrect behavior. In that and earlier library versions, the library didn't take pains to clean up after itself in terms of managing open resources, which caused a large number of issues for users who didn't properly close their own ports before shutting down their application.
To give you and other users a way to properly mimic that old behavior, I've added a new static library method called SerialPort.addShutdownHook(Thread hook)
which you can use to register a Thread object that will be run right as your application is shutting down before the serial ports have been automatically cleaned up. Please try adding your port cleanup functionality using this method in the following beta library version, and let me know if it works as expected for you:
https://www.dropbox.com/t/ywoycnP7qRGjZDCG
(By the way, this function exactly mimics the Java addShutdownHook(Thread hook)
method except that anything you register here is guaranteed to run in-order and before the library has cleaned itself up.)
@hedgecrw nice work, everything works. But the solution is not very pretty.
SerialPort.addShutdownHook(new Thread(() -> Utils.threadSleep(1000)));
Great! Closing this as resolved with today's release v2.9.1.
This is in reference to the last post on Issue #406. A user is experiencing a delay of 5-7 seconds when closing their application.
@sprut666666, is this 5-7 second delay occurring when you call
closePort()
, or does this occur at some other time? Also, please test using the 2.9.1-beta2 version and see if this has improved (I added a fix to ensure that a thread does not try to wait on itself):https://www.dropbox.com/t/eHCqJ4xDQeeAHDBF