> i'd like to do the following. I have two classes that implement
> Runnable, ThreadA and ThreadB. There may be many ThreadA instances,
[quoted text clipped - 3 lines]
> My questions are:
> 1) is this possible
Yes.
> 2) How do i do this?
> i know the following. I create an EventListener in ThreadA and it's
> actionPerformed method will just add the Events to an ArrayList (i am
> not worried about synchronization, since only the instance of ThreadA
> will be modifying that ArrayList). The run method of ThreadA will
> process the queue (ArrayList) as long as it's not empty.
You should worry about synchronization.
I think you are mixing up threads and objects. Let us say that that you
have two objects, call them threadA and threadB, and you start two
threads. Thread-1 runs the run() method of threadA and Thread-2 runs the
run() method of threadB. When the threadB.run() method fires an event, it
is running in Thread-2, so it calls the threadA.actionPerformed() in
Thread-2. But threadA.run() is running in Thread-1, so both Thread-1 and
Thread-2 will be accessing the ArrayList.
> THAT SAID, i am not sure how to register an event in this case? or do i
> need to do that? If i fire an event from ThreadB, will any class that
> has a listener method for that event be able to "catch" that event?
There is nothing to be "caught". The threadB code (running in Thread-2)
calls the actionPerformed() method of threadA (in Thread-2). This is just
an ordinary method call. There is nothing special, no magic that causes
the event listener to run in the other thread.

Signature
Regards,
John McGrath
farseer - 08 Apr 2005 08:33 GMT
Thanks john,
so in reality, i would have to add a reference to the EventListener
class implemented in threadA, to threadB, correct..so that it can call
actionPerformed?
what if i have man instances of threadA, do i have to add a reference
of each of those to threadB so that it can call the actionPerformed on
each? i was hoping there was some sort of way to broad cast a message
to all listeners at the same time? i am guessing threadB would have to
loop thru all references of threadA and call actionPerformed for
each...so infact, not all these instances will "recieve the event" at
the same time, correct?
John McGrath - 08 Apr 2005 18:21 GMT
> so in reality, i would have to add a reference to the EventListener
> class implemented in threadA, to threadB, correct..so that it can call
> actionPerformed?
Yes.
> what if i have man instances of threadA, do i have to add a reference
> of each of those to threadB so that it can call the actionPerformed on
[quoted text clipped - 3 lines]
> each...so infact, not all these instances will "recieve the event" at
> the same time, correct?
Of course. There is no way to guarantee that two things happen at the
exact same time. And in the case of a single processor, they cannot
possibly happen at the exact same time.
For an example of listener handling and notification, take a look at the
AbstractButton class.

Signature
Regards,
John McGrath
farseer - 10 Apr 2005 05:14 GMT
>>And in the case of a single processor, they cannot
>>possibly happen at the exact same time.
well, yeah, i understand that. however with time slicing, the
deviation between the first thread object processed in the loop and the
last is very small.