You can use observer pattern for that. Suppose CacheManager class loads/refreshes data, register that as observer with DataUpdater class to update sequentially. This will be asynchronous approach and is the suggested one in case it takes more than a couple of seconds to refresh data.
1) Whats the difference between synchronized block and method level synchronization?
2)why method level synchronization is not preferred? how does it slows down the performance?
3)I dont know if this question is related to threads, i thought it might be achieved through threads,
If two persons at the same time are trying to buy ticket for the same seat in a Airplane? How to avoid this situation and not let the seat become blocked?
can this be achieved using Threads?
Classic case is having a lock on a queue, with two different condition vars -- one for when the queue is empty, waiting for data, and one for when the queue is full, waiting for room.
ReentrantLock lock;
Condition notEmpty = lock.newCondition();
Condition otherCondition = lock.newCondition ();
...
lock.lock ()
try
{
notEmpty.await ();
..
}
finally
{
lock.unlock ();
}