Code example for Future

Methods: cancel, get, isDone

0
        try (AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(path, StandardOpenOption.READ)) {
            // 
            if (fileChannel.isOpen()) {
                future = fileChannel.read(byteBuffer, 0);
 
                Integer integer = future.get(1, TimeUnit.NANOSECONDS);
                if (future.isDone()) {
                    System.out.println("ok is done");
                } 
            } 
        } catch (Exception e) {
            if (e instanceof TimeoutException) {
                future.cancel(true);
            } 
        } 
    } 
}