s-day06-synchornized代码块解决线程安全问题
This commit is contained in:
@@ -10,14 +10,12 @@ public class TicketTask implements Runnable{
|
||||
while (true) {
|
||||
//如果有票就卖
|
||||
if (ticketCount > 0) {
|
||||
|
||||
//模拟卖票时间
|
||||
try {
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println(Thread.currentThread().getName() + "正在卖第" + ticketCount + "张票");
|
||||
ticketCount--;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user