dev@grizzly.java.net

Re: [Grizzly2.0 - Issue 3] Attaching a Connection object to the SelectionKey

From: Ken Cavanaugh <Ken.Cavanaugh_at_Sun.COM>
Date: Wed, 18 Jun 2008 15:34:08 -0700
ash2k! wrote:
Hi!

Jeanfrancois Arcand-2 wrote:
  
What peoples thinks?

    
I asked some time ago about this thing
http://www.nabble.com/Question-about-http-on-grizzly-tt16846432.html - i
implemented this server (without grizzly, just plain NIO) and i use a simple
hashtable for storing connection related info in it. selectionkey is used as
a key and special class with connection info as a value in hashtable. why
not to implement it like this? i do not use selectionkey attachment bacause
of your blog :) - i agree that there are those disadvantages that you
pointed out. unneded entries from hashtable are removed whenever i close a
channel. also it is rather convenient to iterate throught connections.
  
My concern with using a Hashtable is that it forces a
Hashtable lookup on every read event.  An attachment effectively
just puts the data in a place known the NIO so that it can be
returned directly, avoiding the lookup overhead.

Thanks,

Ken.