-
Notifications
You must be signed in to change notification settings - Fork 813
Open
Description
public class T12_00_Exchanger_Not_Work {
private static Exchanger exchanger = new Exchanger<>();
public static void main(String[] args) {
char[] aI = "1234567".toCharArray();
char[] aC = "ABCDEFG".toCharArray();
new Thread(()->{
for(int i=0; i<aI.length;) {
try {
String t1 = exchanger.exchange("T1");
if ("T2".equals(t1)) {
System.out.print(aI[i]);
i++;
}
exchanger.exchange("T2");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
new Thread(()->{
for(int i=0; i<aC.length;) {
try {
String t2 = exchanger.exchange("T2");
if ("T2".equals(t2)) {
System.out.print(aC[i]);
i++;
exchanger.exchange("T2");
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels