Multi-threaded Linked List access

D

Duke McPherson

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,
 
C

Chris Uppal

Duke said:
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
 
T

tom fredriksen

Duke said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,212
Messages
2,571,101
Members
47,695
Latest member
KayleneBee

Latest Threads

Top