I have a web application where I need to keep track of "most popular" (most visited) articles. Most of the pages (including article pages) in that application displays "most popular" list in sidebar, so this list will be retrieved very often. On the other hand, articles are visited quite often too (approximately 1/2 of page visits are visits to article pages).
What is the best way to keep track of visits and be able to select N most visited articles? As I understand, it should be a concurrent map articleId->visitCount that is sorted by values (visitCounts) and where I can quickly (and threadsafely) increment visitCount and expect map to re-sort itself.