Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JimfsFileChannel the method read why need synchronized #107

Open
SailCoding opened this issue Apr 28, 2020 · 0 comments
Open

JimfsFileChannel the method read why need synchronized #107

SailCoding opened this issue Apr 28, 2020 · 0 comments
Labels
P4 type=enhancement Make an existing feature better

Comments

@SailCoding
Copy link

public int read(ByteBuffer dst) throws IOException {
checkNotNull(dst);
checkOpen();
checkReadable();

int read = 0; // will definitely either be assigned or an exception will be thrown

// the synchronized can be deleted ???
synchronized (this) {
boolean completed = false;
try {
if (!beginBlocking()) {
return 0; // AsynchronousCloseException will be thrown
}
file.readLock().lockInterruptibly();
try {
read = file.read(position, dst);
if (read != -1) {
position += read;
}
file.updateAccessTime();
completed = true;
} finally {
file.readLock().unlock();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} finally {
endBlocking(completed);
}
}

return read;

}

@cpovirk cpovirk added P4 type=enhancement Make an existing feature better labels Apr 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4 type=enhancement Make an existing feature better
Projects
None yet
Development

No branches or pull requests

2 participants