For monitoring purposes I want to maintain a sliding window of operations and results. I have found a data structure to do this quickly but it is not thread-safe. I also don’t care if I drop some data because overall the picture should still be ok, so what’s the fastest way to do this in Java that can scale to hundreds of threads? Is a singleton semaphore with a time-out on tryAcquire the best way? Or would a single threaded executor service that discarded messages when the queue was full be faster
Asked
Active
Viewed 148 times
1
-
You can just use one of the many concurrent queue implementations in the jdk. E.g. `java.util.concurrent.LinkedTransferQueue` it is unbounded and threadsafe. But I am not entirely sure about the performance. Maybe also have a look at another question which is similar: [Which concurrent Queue implementation should I use in Java?](https://stackoverflow.com/questions/1301691/which-concurrent-queue-implementation-should-i-use-in-java) – Lino Jun 04 '20 at 07:39
-
2Could you provide more details and an example? This is IMO far not enough to answer. – akuzminykh Jun 04 '20 at 08:24
-
1There’s a mismatch between your question’s title and body. Do you want a “non-thread safe” solution or a thread safe one? – Holger Jun 04 '20 at 11:04
-
The operation is non-thread safe so I want to do it in a thread safe way – user439407 Jun 05 '20 at 01:57
-
1There’s too little information about what you actually want to do. – Holger Jun 09 '20 at 13:23