2222import java .util .HashMap ;
2323import java .util .List ;
2424import java .util .Map ;
25- import java .util .concurrent .TimeUnit ;
2625import java .util .concurrent .locks .Lock ;
2726import 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