primitive thread communication in practice

Threads can share any data in may ways, but there are some standard patterns to send primitive signals to each other, without any content. These are simple techniques, widely used, battle tested.

* wait/notify [3] – general purpose
* interrupt [1] [3]
* boolean done flag [1]
* join [3]

How about swing?

java.util.concurrent offers a few communication devices. These are not primitive.

[1] these are the 2 standard ways to inform [2] a thread stop itself. See the Thread.stop() api http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Thread.html#stop()

[2] from outside the thread ie another thread.

[3] These techniques cause the receiving thread to act immediately. Shared-data techniques need the receiving thread to poll the shared data.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s