()
| 306 | long timeCheck = 0; |
| 307 | |
| 308 | @Override |
| 309 | public void run() { |
| 310 | while (true) { |
| 311 | try { |
| 312 | Thread.sleep(DELAY_BEFORE_PERSISTING_LIBRARY / 2); |
| 313 | // Wait half the delay before capturing the value |
| 314 | // this will help avoid unnecessary delays when the |
| 315 | // library is updated a bunch in a small interval of time |
| 316 | timeCheck = lastDirtyMarker; |
| 317 | Thread.sleep(DELAY_BEFORE_PERSISTING_LIBRARY / 2); |
| 318 | } catch (InterruptedException ex) { |
| 319 | Logger.getLogger(MediaCache.class.getName()).log(Level.SEVERE, null, ex); |
| 320 | continue; |
| 321 | } |
| 322 | // If the invalidation time stamp changed again wait longer |
| 323 | if (timeCheck != lastDirtyMarker) { |
| 324 | continue; |
| 325 | } |
| 326 | writeLibraryToDisk(); |
| 327 | // If the invalidation stamp wasn't changed then the worker can exit |
| 328 | if (timeCheck == lastDirtyMarker) { |
| 329 | break; |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | }); |
| 334 | writerWorker.start(); |
| 335 | } |
no test coverage detected