pausing message sending & receiving from a java web app
need help in designing a web app that can send and receive messages. it must have a pause functionality. i am having trouble in thinking how can i pause the sending and receiving (threads scare me T_T). the receiving end are clients/开发者_运维技巧servers (using netty)
any suggestions are more than welcome. thanks!!
I agree with Greg/Harry that more information is needed, but let me state that threads got a lot less scary in Java 5 and 6 with the introduction of java.util.concurrent, which is a higher level of abstraction that deals with many real-world threading situations out out the box. If I understand what you want to do correctly, please start out by looking at BlockingQueue.
If you simply want a send/receive mechanism that can be paused, though, set up a finite state machine that has states for INIT, ROUTE, and PAUSE. INIT is for startup before it's ready to do it's job, ROUTE is for when it's waiting for messages to receive to send out, and PAUSE is for when it receives a PAUSE command, and it sits and waits for a RESUME command.
You can run this process (and any others) in a separate thread inside your web app using java.util.concurrent.Executor.
精彩评论