|
22 | 22 | import java.util.HashMap; |
23 | 23 | import java.util.List; |
24 | 24 | import java.util.Map; |
| 25 | +import java.util.concurrent.TimeUnit; |
25 | 26 | import java.util.concurrent.locks.Lock; |
26 | 27 | import java.util.concurrent.locks.ReentrantLock; |
27 | 28 |
|
@@ -78,8 +79,9 @@ public long getTotalSize() { |
78 | 79 | */ |
79 | 80 | public void forceAsyncScan( boolean storeSettingsAfterwards ) { |
80 | 81 |
|
81 | | - if( workerThread == null || workerThread.isAlive() == false ) { |
| 82 | + if( (workerThread == null || workerThread.isAlive() == false) && workerLock.tryLock() ) { |
82 | 83 | workerThread = new Thread( new Worker(this, storeSettingsAfterwards) ); |
| 84 | + workerLock.unlock(); |
83 | 85 | workerThread.start(); |
84 | 86 | } |
85 | 87 |
|
@@ -141,17 +143,16 @@ public StatisticData getUserStats(UserManager user) { |
141 | 143 |
|
142 | 144 | private void generateStats() { |
143 | 145 |
|
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); |
149 | 148 |
|
150 | 149 | // 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) {} |
155 | 156 | } |
156 | 157 |
|
157 | 158 | /** |
@@ -280,10 +281,9 @@ public void run() { |
280 | 281 | if( storeSettings ) |
281 | 282 | quotaManager.workspaceManager.storeSettings(); |
282 | 283 |
|
283 | | - LOGGER.info("finished full quota scan"); |
284 | | - |
285 | 284 | // save duration of execution |
286 | 285 | quotaManager.workerExecutionTime = new Date().getTime() - startTime; |
| 286 | + LOGGER.info("finished full quota scan in ", quotaManager.workerExecutionTime, "ms"); |
287 | 287 | // give dobby a sock |
288 | 288 | quotaManager.workerLock.unlock(); |
289 | 289 | } |
|
0 commit comments