提交 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 { ...@@ -119,7 +119,7 @@ public class FileObjectDiskMapped implements FileObject {
} }
} }
public void close() throws IOException { public synchronized void close() throws IOException {
if (file != null) { if (file != null) {
unMap(); unMap();
file.close(); file.close();
...@@ -135,11 +135,11 @@ public class FileObjectDiskMapped implements FileObject { ...@@ -135,11 +135,11 @@ public class FileObjectDiskMapped implements FileObject {
return FileSystemDiskNioMapped.PREFIX + name; return FileSystemDiskNioMapped.PREFIX + name;
} }
public long length() throws IOException { public synchronized long length() throws IOException {
return file.length(); 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 { try {
mapped.position(pos); mapped.position(pos);
mapped.get(b, off, len); mapped.get(b, off, len);
...@@ -160,7 +160,7 @@ public class FileObjectDiskMapped implements FileObject { ...@@ -160,7 +160,7 @@ public class FileObjectDiskMapped implements FileObject {
this.pos = (int) pos; this.pos = (int) pos;
} }
public void setFileLength(long newLength) throws IOException { public synchronized void setFileLength(long newLength) throws IOException {
checkFileSizeLimit(newLength); checkFileSizeLimit(newLength);
int oldPos = pos; int oldPos = pos;
unMap(); unMap();
...@@ -179,12 +179,12 @@ public class FileObjectDiskMapped implements FileObject { ...@@ -179,12 +179,12 @@ public class FileObjectDiskMapped implements FileObject {
pos = (int) Math.min(newLength, oldPos); pos = (int) Math.min(newLength, oldPos);
} }
public void sync() throws IOException { public synchronized void sync() throws IOException {
mapped.force(); mapped.force();
file.getFD().sync(); 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 // check if need to expand file
if (mapped.capacity() < pos + len) { if (mapped.capacity() < pos + len) {
setFileLength(pos + len); setFileLength(pos + len);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论