Question

I have made my IRC bot and I've run into the problem of flooding. I'm trying to figure out a way to space out the messages so if 10 people all execute a command at the same time it doesn't excess flood the bot. How would I do this? I was thinking of implementing a Queue but I'm not sure where to go after that.

I'm not using any frameworks for this bot nor do I want to switch to any framework (unless its extremely easy).

Was it helpful?

Solution

Sure, you could use a queue.

Let one thread put stuff on the queue, let another thread process items from the queue in a nice pace. It's an instance of the classical consumer / producer pattern.

Just make sure that you don't let your queue eat up all your memory in case of excessive flooding. (You could for instance just drop messages if the queue is full.)

OTHER TIPS

java.util.concurrent probably has what you want. An Executor or just a BlockingQueue for example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top