int tickets = 100;
String string = "";
executor.execute(new Runnable() {
@Override
public void run() {
while (tickets > 0) {
synchronized (string) {
try {
if (tickets > 0) {
System.out.println(Thread.currentThread().getName()
+ "卖出了第" + (tickets--) + "张票");
Thread.sleep(1000);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
});