Either sleep() or wait() in a synchronized block
While looking into #24792 (moved), I found that we're calling this.wait() here without being in a synchronized method or block. That gets us a IllegalMonitorStateException. The only reason why we never ran into one of those (or never noticed?) is that most clients first open /collector.html which triggers an index.json file download in the background before opening actual directory listing pages.
We should fix this. Two options: use Thread.sleep() instead of this.wait(), or wrap this.wait() inside synchronized possibly even combined with this.notifyAll(). I'd say let's do the latter. I'm attaching a quickly tested branch in a second.