Skip to content

Commit

Permalink
fix:修改sonar提示的bug,Reliability 提升到B
Browse files Browse the repository at this point in the history
  • Loading branch information
gio-yanruixue authored and tianhui12 committed Dec 22, 2021
1 parent 77dc04a commit 6eeae7f
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class MultiProcessDataSharer implements IDataSharer {

private volatile boolean mLoaded;
private MappedByteBuffer mMappedByteBuffer;
private RandomAccessFile randomAccessFile;
private FileChannel mFileChannel;
private final Map<String, SharedEntry> mSharedEntries = new HashMap<>();
private int mCurrentPosition = 0;
Expand All @@ -65,7 +66,9 @@ public void run() {
}.start();
}

private void awaitLoadedLocked() {
// synchronized 是可重入锁
// 加上synchronized 规避sonar检查wait() 在锁中调用
private synchronized void awaitLoadedLocked() {
while (!mLoaded) {
try {
Logger.d(TAG, "awaitLoadedLocked");
Expand All @@ -86,7 +89,7 @@ private void loadFromDisk() {
}
File file = mContext.getFileStreamPath(mName);
try {
RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
randomAccessFile = new RandomAccessFile(file, "rw");
mFileChannel = randomAccessFile.getChannel();
mMappedByteBuffer = mFileChannel.map(FileChannel.MapMode.READ_WRITE, 0, (long) mMaxSize * SharedEntry.MAX_SIZE);
incrementLoadFromDisk();
Expand Down

0 comments on commit 6eeae7f

Please sign in to comment.