I'm going to make a pretty big assumption, which is that when you say you "store the views count & no Of likes", you mean that they are stored in a query-friendly format (ie, an SQL Database or equivalent). The main reason you want to store information in-memory, then, is to cache the data, thereby reducing the number of database calls required to generate a page. Is this assumption correct?
If so, then I think you are over-complicating the issue. Rather than using complex data structures to maintain your information, treat it as a simple cache structure. Here's a highly simplified, pseudocode example of how it would work:
class TopXCache extends Runnable
{
Object[] cachedData;
int secondsToTimeOut;
String sqlQueryToRefreshCache;
boolean killSwitch = false;
constructor(int itemsToKeepInCache, int secondsToTimeOut, String sqlQueryToRefreshCache)
{
this.secondsToTimeOut = secondsToTimeOut;
this.sqlQueryToRefreshCache = sqlQueryToRefreshCache;
this.cachedData = new Object[itemsToKeepInCache];
}
void run() // The method the thread will execute
{
while(!killSwitch) // Allows for "poison pill" shutdown
{
cachedData = executeQuery(sqlQueryToRefreshCache);
wait(secondsToTimeOut);
}
}
void kill()
{
killSwitch = true;
}
}
To create a list, instantiate it with a poll time (secondsToTimeOut), an SQL query to run which will return the latest copy of the data (sqlQueryToRefresh), and the number of items you want in your list (itemsToKeepInCache, in your case, 40).
Then start up a thread which can execute the above (or a scheduled task, or a cron library task, whatever else you're using to manage timed events in your application,) and periodically your cache will refresh itself. If your system shuts down unexpectedly, then it will automatically rebuild itself from the database once the thread is restarted.
This is the basis of an incredibly simple cache. You can make it more complicated if you like, set it up as a singleton, add a "forceRefresh()" method to update the data outside the current refresh window, set it up to hold and refresh multiple caches on a single thread, or even go the whole hog and use a third party caching library.
Caching is the normal solution to this sort of problem though, and one which is normally easier to understand and maintain in the long term.