Reputation: 794
In my J2EE web app, I have to send a count for every Web API call to an isolated thread for counting the number of calls. Possibilities include:
a) Use an atomic long. I think that would cause contention in case I have millions of calls in a minute. As, all the threads will try to update a single variable.
b) Use a shared queue. Every request processing thread will insert into the queue, and the dedicated counter thread will dequeue from that queue and increment the count.
c) Use actor model, say using Akka library. Send an asynchronous message to the actor, and that will add it up to the count.
My question is how does method (b) compare to (c). What are the pros and cons, and how they are different at low level?
Upvotes: 1
Views: 811
Reputation: 23
In your case I believe Actor model should be a better option. Pros with Akka-
There is a similar question at- When to use actors instead of messaging solutions such as WebSphere MQ or Tibco Rendezvous?
Upvotes: 1