Skip to content

Commit 61d54cb

Browse files
committed
fixed stats generation waiting mechanism
1 parent 4032702 commit 61d54cb

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

src/main/java/de/unirostock/sems/cbarchive/web/QuotaManager.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.HashMap;
2323
import java.util.List;
2424
import java.util.Map;
25+
import java.util.concurrent.TimeUnit;
2526
import java.util.concurrent.locks.Lock;
2627
import java.util.concurrent.locks.ReentrantLock;
2728

@@ -78,8 +79,9 @@ public long getTotalSize() {
7879
*/
7980
public void forceAsyncScan( boolean storeSettingsAfterwards ) {
8081

81-
if( workerThread == null || workerThread.isAlive() == false ) {
82+
if( (workerThread == null || workerThread.isAlive() == false) && workerLock.tryLock() ) {
8283
workerThread = new Thread( new Worker(this, storeSettingsAfterwards) );
84+
workerLock.unlock();
8385
workerThread.start();
8486
}
8587

@@ -141,17 +143,16 @@ public StatisticData getUserStats(UserManager user) {
141143

142144
private void generateStats() {
143145

144-
if( (workerThread == null || workerThread.isAlive() == false) && workerLock.tryLock() ) {
145-
workerThread = new Thread( new Worker(this, true) );
146-
workerLock.unlock();
147-
workerThread.start();
148-
}
146+
// start new thread
147+
forceAsyncScan(false);
149148

150149
// wait for the thread to finish
151-
while( workerThread.isAlive() ) {
152-
workerLock.lock();
153-
}
154-
workerLock.unlock();
150+
try {
151+
if( workerThread.isAlive() ) {
152+
if( workerLock.tryLock(workerExecutionTime * 4, TimeUnit.MILLISECONDS) )
153+
workerLock.unlock();
154+
}
155+
} catch (InterruptedException e) {}
155156
}
156157

157158
/**
@@ -280,10 +281,9 @@ public void run() {
280281
if( storeSettings )
281282
quotaManager.workspaceManager.storeSettings();
282283

283-
LOGGER.info("finished full quota scan");
284-
285284
// save duration of execution
286285
quotaManager.workerExecutionTime = new Date().getTime() - startTime;
286+
LOGGER.info("finished full quota scan in ", quotaManager.workerExecutionTime, "ms");
287287
// give dobby a sock
288288
quotaManager.workerLock.unlock();
289289
}

0 commit comments

Comments
 (0)