FileChannel channel
doesn't has volatile
, but boolean closed
has volatile
. Below is in Java 8 standard library.
public class FileInputStream{
private FileChannel channel = null;
private volatile boolean closed = false;
}
FileChannel channel
doesn't has volatile
, but boolean closed
has volatile
. Below is in Java 8 standard library.
public class FileInputStream{
private FileChannel channel = null;
private volatile boolean closed = false;
}
The field is only assigned in a synchronized block, so volatile is not required. Visibility is guaranteed by the monitor lock.
public FileChannel getChannel() {
synchronized (this) {
if (channel == null) {
channel = FileChannelImpl.open(fd, path, true, false, this);
}
return channel;
}
}