The Java(tm) FAQ -- Threads

Copyright        Table of Contents        Chapters:   1   2   3   4   5   6   7   8   9   10   11

Outline


Creating and Controlling Threads


Q9.1
What is a thread?

See also: Q9.2, Q9.6, Q9.7, Q9.8


Q9.2
How do I create a thread and start it running?

CreateThreadExample.html

See also: Q1.21, Q9.1, Q9.3


Q9.3
How does Thread's stop method work -- can I restart a stopped thread?

See also: Q9.2, Q9.4, Q9.5, Q9.7, Q9.10


Q9.4
How should I stop a thread so that I can start a new thread later in its place?

See also: Q9.2, Q9.3, Q9.16


Q9.5
How do I specify pause times in my program?

SleepExample.html

See also: Q1.6, Q2.23, Q9.10


Thread Interactions


Q9.6
Why is thread synchronization important for multithreaded programs?

See also: Q9.7, Q9.8


Q9.7
What is a monitor?

See also: Q9.8, Q9.10


Q9.8
How does the synchronized keyword work?

SynchronizationExample.html

See also: Q9.7, Q9.8


Q9.9
What objects do static synchronized methods use for locking?

See also: Q1.30, Q2.23, Q9.7, Q9.8


Q9.10
How do the wait and notifyAll/notify methods enable cooperation between threads?

WaitNotifyExample.html

See also: Q9.11


Q9.11
How do I achieve the effect of condition variables if the Java platform provides me with only wait and notifyAll/notify methods?

ConditionVariableExample.html

See also: Q9.10


Q9.12
How do I make one thread wait for one or more other threads to finish?

JoinExample.html

See also: Q9.5, Q9.10


Q9.13
What do I use the yield method for?

See also: Q9.15


Q9.14
Does the Java Virtual Machine protect me against deadlocks?

DeadlockExample.html

See also: Q9.7, Q9.8


User Threads versus System Threads


Q9.15
Why does my multithreaded program run fine on Windows NT/95 but block on Solaris?

See also: Q9.13


Q9.16
Why do so many applets run a copy of themselves in a separate thread rather than just running as they are?

SystemThreadsExample.html

See also: Q4.2, Q4.16, Q9.4, Q9.17


Q9.17
How can it be that putting an applet thread to sleep in the wrong place can block other applets from running?

BlockAWTThreadExample.html

See also: Q4.16, Q6.4, Q7.3, Q8.1, Q8.5, Q9.16


Q9.18
Can I have a thread wait on an event from the operating system?