Java Reference
In-Depth Information
// Create and start two helper services
for (int i = 1; i <= 2; i++) {
LatchHelperService lhs = new LatchHelperService(i, latch);
lhs.start();
}
}
}
Main service is waiting for helper services to start...
Service #2 starting in 8 seconds...
Service #1 starting in 15 seconds...
Service #2 has started...
Service #1 has started...
Main service has started...
Exchangers
An exchanger is another form of a barrier. Like a barrier, an exchanger lets two threads wait for each other at a
synchronization point. When both threads arrive, they exchange an object and continue their activities. This is useful
in building a system where two independent parties need to exchange information from time to time. Figure 6-13
through Figure 6-15 depict how an exchanger works with two threads and lets them exchange an object.
E
X
C
H
A
N
G
E
R
Figure 6-13. Two threads perform their work independently
E
X
C
H
A
N
G
E
R
Figure 6-14. One thread arrives at the exchange point and waits for another thread to arrive
 
 
Search WWH ::




Custom Search