mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-21 15:19:53 +01:00
AtomicBoolean is not needed.
This commit is contained in:
@@ -1,14 +1,13 @@
|
|||||||
package net.sf.briar.db;
|
package net.sf.briar.db;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
|
|
||||||
class DatabaseCleanerImpl implements DatabaseCleaner, Runnable {
|
class DatabaseCleanerImpl implements DatabaseCleaner, Runnable {
|
||||||
|
|
||||||
private final AtomicBoolean stopped = new AtomicBoolean(false);
|
private final Object lock = new Object();
|
||||||
private final Thread cleanerThread = new Thread(this);
|
private final Thread cleanerThread = new Thread(this);
|
||||||
|
|
||||||
private volatile Callback callback;
|
private volatile Callback callback;
|
||||||
private volatile long msBetweenSweeps;
|
private volatile long msBetweenSweeps;
|
||||||
|
private volatile boolean stopped = false; // Locking: lock
|
||||||
|
|
||||||
public void startCleaning(Callback callback, long msBetweenSweeps) {
|
public void startCleaning(Callback callback, long msBetweenSweeps) {
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
@@ -17,10 +16,10 @@ class DatabaseCleanerImpl implements DatabaseCleaner, Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void stopCleaning() {
|
public void stopCleaning() {
|
||||||
stopped.set(true);
|
|
||||||
// If the cleaner thread is waiting, wake it up
|
// If the cleaner thread is waiting, wake it up
|
||||||
synchronized(stopped) {
|
synchronized(lock) {
|
||||||
stopped.notifyAll();
|
stopped = true;
|
||||||
|
lock.notifyAll();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
cleanerThread.join();
|
cleanerThread.join();
|
||||||
@@ -33,10 +32,10 @@ class DatabaseCleanerImpl implements DatabaseCleaner, Runnable {
|
|||||||
if(callback.shouldCheckFreeSpace()) {
|
if(callback.shouldCheckFreeSpace()) {
|
||||||
callback.checkFreeSpaceAndClean();
|
callback.checkFreeSpaceAndClean();
|
||||||
} else {
|
} else {
|
||||||
synchronized(stopped) {
|
synchronized(lock) {
|
||||||
if(stopped.get()) break;
|
if(stopped) break;
|
||||||
try {
|
try {
|
||||||
stopped.wait(msBetweenSweeps);
|
lock.wait(msBetweenSweeps);
|
||||||
} catch(InterruptedException ignored) {}
|
} catch(InterruptedException ignored) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user