On Thu, Mar 12, 2009 at 12:13 PM, Oscar <[email protected]> wrote:
> Thanks for you reply.I've finished the rough version, running all the
> business-side code in the main thread.
>
> void main()
> {
>  // initialize all the mina stuff
>
>  //fetching the message from the queue
> }
>
>
> void messageReceived(...)
> {
>  // put the message into the queue.
> // need to lock the queue
> }
Note on implementation: Use a blocking queue, that way all thread
safety is managed for you... as well as the Main thread gets simple.

(see: 
http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/BlockingQueue.html)

Example without using generics...
BlockingQueue queue = new LinkedBlockingQueue();

void main() {
  // Start mina
  while(true) {
    process(queue.take());
  }
}

void messageReceived(...) {
  queue.put(message);
}
-- 
Thomas Harning Jr.

Reply via email to