[concurrency-interest] Tree{Map,Set}

Pollachi, Saikumar Sai.Kumar at ca.com
Fri Apr 1 09:26:33 EST 2005


Hi!

I missed the import statements in the code snippet. I am using LinkedQueue of Doug Lea's concurrent library.

The class is  packaged in EDU.oswego.cs.dl.util.concurrent.

In my persist() method I am synchronizing on 'head_' (a LinkedNode) instance variable in LinkedQueue class. Will this cause any dead locks when put(Object) and get() methods are being called in different threads?

Thanks...

-----Original Message-----
From: David Holmes [mailto:dholmes at dltech.com.au]
Sent: Thursday, March 31, 2005 6:48 PM
To: Pollachi, Saikumar; concurrency-interest at altair.cs.oswego.edu
Subject: RE: [concurrency-interest] Tree{Map,Set}


I'm not at all clear on what you have done. What is a LinkedQueue? How does
it perform synchronization?

David Holmes

> -----Original Message-----
> From: concurrency-interest-bounces at cs.oswego.edu
> [mailto:concurrency-interest-bounces at cs.oswego.edu]On Behalf Of
> Pollachi, Saikumar
> Sent: Friday, 1 April 2005 4:58 AM
> To: concurrency-interest at altair.cs.oswego.edu
> Subject: RE: [concurrency-interest] Tree{Map,Set}
>
>
>
> Hi!
>
> I am a silent member of the group. I enjoy reading the mails from this
> group. Can somebody tell me if there is any possibility of deadlocks in
> this code. I extended LinkedQueue to create  a PersistentQueue. It works
> fine most of the time. Some time I suspect there is a dead lock.
>
>
> public class PersistentQueue
>     extends LinkedQueue
> {
>     private void restoreQueue()
>     {
> 	...
>     }
>
>     private void buildQueue() throws InterruptedException, IOException
>     {
> 		...
>     }
>
>     public void put(Object item) throws InterruptedException
>     {
>         //Object[] items = getSnapshot(item);
>         super.put(item);
>         persist();
>     }
>
>     public Object take() throws InterruptedException
>     {
>         Object obj = super.take();
>         persist();
>         return obj;
>     }
>
>     private void persist(Object[] items)
>     {
>         if (items != null)
>         {
>             int size = items.length;
>             ObjectOutputStream out = null;
>
>             try
>             {
>                 out = new ObjectOutputStream(new
> FileOutputStream(queuePath, false));
>
>                 for (int i = 0; i < size; i++)
>                 {
>                     out.writeObject(items[i]);
>                 }
>
>                 out.flush();
>                 out.close();
>             }
>             catch (IOException ioe)
>             {
>                 logger.logp(Level.WARNING, "PersistentQueue",
> "buildQueue()",
>                             "Failed to persist the Queue..: " +
> ioe.getMessage(), ioe);
>             }
>         }
>     }
>
>     private void persist()
>     {
>         if (queuePath == null)
>         {
>             return;
>         }
>
>         ObjectOutputStream out = null;
>
>         boolean retry = false;
>         do
>         {
>             retry = false;
>             try
>             {
>                 out = new ObjectOutputStream(new
> FileOutputStream(queuePath, false));
>                 synchronized (head_)
>                 {
>                     LinkedNode head = head_.next;
>                     while (head != null)
>                     {
>                         if (head.value != null)
>                         {
>                             out.writeObject(head.value);
>                         }
>                         head = head.next;
>                     }
>                 }
>             }
>             catch (IOException ioe)
>             {
>                 //possible that the directory or file does not exist!
>                 //try to create it and if it fails then throw an
> exception
>                 logger.logp(Level.WARNING, "PersistentQueue",
> "persist()",
>                             "Failed to persist the Queue..: " +
> ioe.getMessage(), ioe);
>                 logger.logp(Level.FINE, "PersistentQueue", "persist()",
>                             "Attempting to create the directory and then
> persist.");
>                 createDir(queuePath);
>                 retry = true;
>             }
>             finally
>             {
>                 try
>                 {
>                     if(out != null)
>                     {
>                         out.flush();
>                         out.close();
>                     }
>                 }
>                 catch (IOException ioe)
>                 {
>                     logger.logp(Level.FINE, "PersistentQueue",
> "persist()",
>                                 "Failed to close the file stream : " +
> ioe.getMessage());
>
>                 }
>             }
>         }while(retry);
>     }
>
> }
>
> Thanks
>
> Saikumar Pollachi
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
>





More information about the Concurrency-interest mailing list