synchronize threads

N

Neel

Hi friends,
I have a small query.
'm new to Java so was unable to figure out how to solve it.
[ I couldn't find that group dedicated to Java Threads so posted my
query in this group.]

My query is...

I have a linked list in which ONE thread always inserts data and
MULTIPLE threads (say servicing threads) fetches data and process the
data.....

I want this to be synchronized (race condition should not happen).

Also I maintain a count of number of consuming threads (say, int
thread_count).

This might make query little confusing but... what I want is, I
maintain count of total threads that can fetch data.
whenever anyone has finished serving one customer, it is terminated
and whenever new customer in inserted in the linked list, a new
service thread is created and thread_count is incremented.

The situation where synchronizing thread_count comes into picture
is.... "when the servicing thread terminates, it check the
thread_count. If the value is less than 2, it will not terminate but
continue in infinite loop. I want there should be atleast ONE service
thread always there.

Thanks in advance.
 
M

Mark Space

Neel said:
Also I maintain a count of number of consuming threads (say, int
thread_count).

Hmm, I smell homework. Classic producer consumer problem anyone?


The situation where synchronizing thread_count comes into picture
is.... "when the servicing thread terminates, it check the
thread_count. If the value is less than 2, it will not terminate but
continue in infinite loop. I want there should be atleast ONE service
thread always there.

That's a good one. It kinda prevent the student from just copying and
pasting a solution from the web. It's almost like your professor wants
to make sure you understand the material.


I think I'd need the whole problem statement though to help you, and it
might also be helpful to show us what code you've written. Also, did
you ask any TA's or classmates for help? What have they said?

Also, are you allowed to use objects from java.util.concurent? They
might help if you are.
 
M

Mike Schilling

Lew said:
I found Brian Goetz's /Java Concurrency in Practice/ necessary to
begin to understand concurrent programming in Java.

Is it better than Doug Lea's Concurrent Programming in Java? (Note
that Doug Lea wrote most of what's now java.util.concurrent.)
 
D

Daniel Pitts

Mike said:
Is it better than Doug Lea's Concurrent Programming in Java? (Note
that Doug Lea wrote most of what's now java.util.concurrent.)
Doug Lea was a co-author of /Java Concurrency in Practice/, as was
Joshua Bloch, and a few others.
 

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

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,076
Latest member
OrderKetoBeez

Latest Threads

Top