سؤال

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).

هل كانت مفيدة؟

المحلول

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.)

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top