I am working on a multi-threaded based Web application developed using Java EE.
I have two threads inside that application similar to a producer and consumer, where one thread continuously reads the data from a third party API (Socket connection), and updates it to a cache. The other thread (consumer) continuously tries to read from the cache.
My question is if there is any way that I can improve the performance of the consumer thread (I mean it only reads the data from the cache) when and only there is a change in data.
Sure, use a BlockingQueue (choose an implementation like
ArrayBlockingQueuefor example). It will block (suspend) the consumer callingtakeuntil there is data available in the buffer.