Skip to content

Commit

Permalink
Fix concurrency problem.
Browse files Browse the repository at this point in the history
  • Loading branch information
horizonzy committed Feb 11, 2024
1 parent f389666 commit 1796a4d
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class BufferedReadChannel extends BufferedChannelBase {

long invocationCount = 0;
long cacheHitCount = 0;
private long fileSize = -1;
private volatile long fileSize = -1;
final boolean sealed;

public BufferedReadChannel(FileChannel fileChannel, int readCapacity) {
Expand Down Expand Up @@ -75,7 +75,11 @@ public int read(ByteBuf dest, long pos) throws IOException {
public long size() throws IOException {
if (sealed) {
if (fileSize == -1) {
fileSize = validateAndGetFileChannel().size();
synchronized (this) {
if (fileSize == -1) {
fileSize = validateAndGetFileChannel().size();
}
}
}
return fileSize;
} else {
Expand Down

0 comments on commit 1796a4d

Please sign in to comment.