s-day06-synchornized代码块解决线程安全问题

This commit is contained in:
2026-08-06 11:22:55 +08:00
parent ecacfc7ead
commit 17f951ccc3
3 changed files with 57 additions and 2 deletions
@@ -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 {