Re: multiple threads grabbing items from a vector
From: Jose Solorzano (jhsolorz_at_hotmail.com)
Date: 01/13/05
- Next message: JS: "Re: How to cut strings?"
- Previous message: klynn47_at_comcast.net: "Re: How to cut strings?"
- In reply to: johndesp_at_us.ibm.com: "multiple threads grabbing items from a vector"
- Next in thread: johndesp_at_us.ibm.com: "Re: multiple threads grabbing items from a vector"
- Reply: johndesp_at_us.ibm.com: "Re: multiple threads grabbing items from a vector"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 12 Jan 2005 16:11:16 -0800
johndesp@us.ibm.com wrote:
> Hi.
>
> I want to startup 3 threads which will access elements of a Vector
and
> perform an action based upon the value in the vector. I want to each
> thread to get priority to the Vector to grab the next element in
order
> that the particular thread completed enacting on the previous Vector
> element.
>
> Forinstance, Assuming each thread gets started in order..
>
> The first three elements of the vector would get executed in order
>
> Thread 0 ==> element 0
> Thread 1 ==> element 1
> Thread 2 ==> element 2
>
> However if Thread 1 finished before the others it would grab the next
> vector element..
>
> Thread 1 ==> element 3
> Thread 2 ==> element 4
> Thread 0 ==> element 5
>
> I can get the threads started but thread 0 always seems to have a
> "lock" on the Vector and the other threads can't get involved..
>
> I would appreciate it if someone could provide a solution and perhaps
> some psuedo code to make this happen. Like I said before I can get
all
> 3 threads to start , but thread 0 hogs up the Vector...
>
> thanks
I don't think a lock is the problem. Each method
in Vector is synchronized, but that doesn't mean
it locks the vector all the way thru while you
iterate it.
Thread 0 probably finishes the operation before
other threads even get a chance to start. If
you really need the threads to synchronize their
execution, you must use Object.wait() and
Object.notify/notifyAll().
Jose Solorzano
- Next message: JS: "Re: How to cut strings?"
- Previous message: klynn47_at_comcast.net: "Re: How to cut strings?"
- In reply to: johndesp_at_us.ibm.com: "multiple threads grabbing items from a vector"
- Next in thread: johndesp_at_us.ibm.com: "Re: multiple threads grabbing items from a vector"
- Reply: johndesp_at_us.ibm.com: "Re: multiple threads grabbing items from a vector"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|