문제

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