I am writing a multithreaded Java application which gets info from a websocket
and bufferized
it on a LinkedList
, and I have another thread which gets this info from this linked list, like a queue, first in first out, and also I have a Thread.sleep(1)
to make it wait 1 millisecond before it tries to get the info from the linked list again. Sometime I don't know what is happening but it seems to wait more than 1 millisecond after some hours, like the consumer thread is down or too slow. Is there any better alternative than Thread.sleep
? Should I bufferize this info using another data structure?
By the way this LinkedList
is inside a singleton so I can produce the info in one thread and consume in another.
Thanks