mina-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Harning Jr." <harni...@gmail.com>
Subject Re: how can I run all the logic in the main thread?
Date Thu, 12 Mar 2009 16:41:15 GMT
On Thu, Mar 12, 2009 at 12:13 PM, Oscar <ro4tub@gmail.com> 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.

Mime
View raw message