thread communication

Hi everybody , just some simple questions that involves thread communication. Is there 3 ways to communicate between threads.

1. pipe streams

2. static variables

3. pass a reference ( two threads in a program each has a reference of the other.

thanks for any replys

martin

[323 byte] By [mmartinh] at [2007-9-26 2:15:48]
# 1
Those 3, and many others.
DrClap at 2007-6-29 9:13:24 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 2
what are they then? :)
mmartinh at 2007-6-29 9:13:24 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 3

Threads are objects of the Thread class and inherit from the Object class. A new thread is created by either extending Thread or creating a class that implements the Runnable interface which only has one method public void run(). You put the code you want to execute in this method. Then either instantiate your subclass of Thread and call the start() method or pass an instance of your class that implements the Runnable interface into the constructor of an instance of class Thread and call start().

Threads execute independently of the main thread and can carry on running after the main thread has died except if it is set as a daemon thread.

In other words they have the properties you want them to have and can communicate however you want them to.

You do have to think carefully how your program may proceed though particularly as threads can have different states-which is the key to understanding threads.

ogrijon at 2007-6-29 9:13:24 > top of Java-index,Archived Forums,New To Java Technology Archive...