[concurrency-interest] PooledLinkedBlockingQueue

Jean Morissette jean.morissette666@videotron.ca
Wed, 03 Nov 2004 21:20:23 -0500


Doug Lea wrote:
>>Without wanting to look at what you've done to SUN's LinkedList,
> 
> To avoid future similar reactions, I pulled that posting from the list
> archives. 

Excuse me.

To help the discussion, I give here only my code for the pool:

   Entry[] pool = new Entry[5];
   int poolSize;

   private Entry alloc(Object o, Entry successor, Entry predecessor) {
     Entry e;

     if (poolSize == 0) {
       for (int i = 0; i < pool.length; i++) {
         pool[i] = new Entry(null, null, null);
         poolSize++;
       }
     }

     poolSize--;
     e = pool[poolSize];
     e.element = o;
     e.next = successor;
     e.previous = predecessor;
     return e;
   }

   private void free(Entry e) {
     e.next = e.previous = null;
     e.element = null;
     if (poolSize < pool.length) {
       pool[poolSize] = e;
       poolSize++;
     }
   }