提交 0fec2501 authored 作者: Thomas Mueller's avatar Thomas Mueller

Some people reported NullPointerException in FileObjectDiskMapped. The most…

Some people reported NullPointerException in FileObjectDiskMapped. The most likely explanation is that multiple threads access the same object at the same time. Therefore, the public methods in this class are now synchronized.
上级 ee3c4db3
......@@ -119,7 +119,7 @@ public class FileObjectDiskMapped implements FileObject {
}
}
public void close() throws IOException {
public synchronized void close() throws IOException {
if (file != null) {
unMap();
file.close();
......@@ -135,11 +135,11 @@ public class FileObjectDiskMapped implements FileObject {
return FileSystemDiskNioMapped.PREFIX + name;
}
public long length() throws IOException {
public synchronized long length() throws IOException {
return file.length();
}
public void readFully(byte[] b, int off, int len) throws EOFException {
public synchronized void readFully(byte[] b, int off, int len) throws EOFException {
try {
mapped.position(pos);
mapped.get(b, off, len);
......@@ -160,7 +160,7 @@ public class FileObjectDiskMapped implements FileObject {
this.pos = (int) pos;
}
public void setFileLength(long newLength) throws IOException {
public synchronized void setFileLength(long newLength) throws IOException {
checkFileSizeLimit(newLength);
int oldPos = pos;
unMap();
......@@ -179,12 +179,12 @@ public class FileObjectDiskMapped implements FileObject {
pos = (int) Math.min(newLength, oldPos);
}
public void sync() throws IOException {
public synchronized void sync() throws IOException {
mapped.force();
file.getFD().sync();
}
public void write(byte[] b, int off, int len) throws IOException {
public synchronized void write(byte[] b, int off, int len) throws IOException {
// check if need to expand file
if (mapped.capacity() < pos + len) {
setFileLength(pos + len);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论