Skip to content

Commit 118a52f

Browse files
committed
fixed waiting bug for stats generation
1 parent 61d54cb commit 118a52f

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

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

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

@@ -119,12 +118,11 @@ public long updateWorkspace( String workspaceId ) {
119118
public StatisticData getStats() {
120119

121120
// if cache is ok
122-
if( stats != null && statsTimestamp != null && (new Date().getTime() - statsTimestamp.getTime() + workerExecutionTime)/1000 < Fields.MAX_STATS_AGE )
123-
return stats;
124-
else {
121+
if( stats == null || statsTimestamp == null || (new Date().getTime() - statsTimestamp.getTime() + workerExecutionTime)/1000 > Fields.MAX_STATS_AGE )
125122
generateStats();
126-
return stats;
127-
}
123+
124+
LOGGER.debug( "return stats, generated at ", stats.getGenerated() );
125+
return stats;
128126
}
129127

130128
public StatisticData getUserStats(UserManager user) {
@@ -143,16 +141,19 @@ public StatisticData getUserStats(UserManager user) {
143141

144142
private void generateStats() {
145143

144+
LOGGER.debug( "start generation of new stats, old are generated at: ", stats.getGenerated() );
145+
146146
// start new thread
147147
forceAsyncScan(false);
148148

149149
// wait for the thread to finish
150150
try {
151-
if( workerThread.isAlive() ) {
152-
if( workerLock.tryLock(workerExecutionTime * 4, TimeUnit.MILLISECONDS) )
153-
workerLock.unlock();
154-
}
155-
} catch (InterruptedException e) {}
151+
workerThread.join( workerExecutionTime > 5 ? workerExecutionTime * 2 : 250 );
152+
} catch (InterruptedException e) {
153+
LOGGER.debug(e, "Aborted waiting for background task");
154+
}
155+
156+
LOGGER.debug( "stop waiting for generation, new stats are from: ", stats.getGenerated() );
156157
}
157158

158159
/**

0 commit comments

Comments
 (0)