Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

Multi-threaded Linked List access

Thread view: 
Duke McPherson - 20 Feb 2006 22:28 GMT
I'm writing a series of methods to support reading, writing, swapping,
and searching for elements in a linked list in a multi-threaded
environment.  The main problem is I'm not sure how to reference and use
the same linked list throughout.  For example, if I'm trying to read an
element from the linked list, and the element doesn't exist, I want to
wait until it does exist.  I'm using wait / notify to do this, but
after notifying that a new element exists, the wait just keeps on
waiting without breaking out of it.

Can anyone recommend general design guidelines for constructing classes
which would support this behavior?  I've tried many different things,
and I still can't get the results I need.

Thanks,
xabo - 21 Feb 2006 09:13 GMT
see the producer cosumer exmaple in
http://java.sun.com/docs/books/tutorial/essential/threads/synchronization.html
this is closely related to what you want to achieve
Chris Uppal - 21 Feb 2006 09:19 GMT
> Can anyone recommend general design guidelines for constructing classes
> which would support this behavior?  I've tried many different things,
> and I still can't get the results I need.

Get hold of a copy of Doug Lea's book: "Concurrent Programming in Java: Design
Principles and Patterns", and read it.

It's that simple...

Also (/not/ "instead"), if you are using J1.5 then see the new
java.util.concurrent package.

   -- chris
tom fredriksen - 21 Feb 2006 23:13 GMT
> I'm writing a series of methods to support reading, writing, swapping,
> and searching for elements in a linked list in a multi-threaded
> environment.  

First off, read the recommended literature in the other posts.

Basically, write an ordinary linked list, plus the following rule, only
one thread can access when changing the structure.

> The main problem is I'm not sure how to reference and use
> the same linked list throughout.

What do you mean by this, cause I dont understand how your example
explains your statement.

> For example, if I'm trying to read an
> element from the linked list, and the element doesn't exist, I want to
> wait until it does exist.  
> I'm using wait / notify to do this, but
> after notifying that a new element exists, the wait just keeps on
> waiting without breaking out of it.

When you add a new object, you need to check a private list which
contains the things you are waiting for and which performs a notify if
it finds it in the list, but only after it has been inserted.

Hope that helps.  If not, I wont bother you again:)

/tom


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.