Community
Participate
Working Groups
There is no way to check if an Async file handle has already been closed prior to calling close() because there is no readonly method to determine this value safely. Upon executing multiple calls to close an expected exception is thrown. Use case: multiple threads/consumers performing work from data read from AsyncFile file, and fatal error in file records for processing exists and is reported at point t(n) by thread or consumer. File processing is required to be terminated where hundreds of thousands of lines are left to be processed. There is no way to check if file is already closed and gracefully terminate without exception below if file is already partially completed. Current work around is using AtomicBoolean variable to determine if file is closed before calling close or end in both endHandler and while terminating regular execution within file processing handlers. Possible solution, expose close state as threadsafe and readonly to avoid clumsy or expensive exception handling in multiple file termination paths with different handler events private void checkClosed() { if (this.closed) { throw new IllegalStateException("File handle is closed"); } }