4 回答

TA貢獻(xiàn)64條經(jīng)驗(yàn) 獲得超115個(gè)贊
關(guān)鍵在
System.out.println(String.format("thread:?%s?,?tiketnum?=?%d?do?some?thing",Thread.currentThread().getName(),ticket--));
如果將ticket--移出來(lái),改寫成
System.out.println(String.format("thread:?%s?,?tiketnum?=?%d?do?some?thing",Thread.currentThread().getName(),ticket));
ticket--;
輸出就正常了
thread:?th0?,?tiketnum?=?10?do?some?thing
thread:?th0?,?tiketnum?=?9?do?some?thing
thread:?th0?,?tiketnum?=?8?do?some?thing
thread:?th0?,?tiketnum?=?7?do?some?thing
thread:?th0?,?tiketnum?=?6?do?some?thing
thread:?th0?,?tiketnum?=?5?do?some?thing
thread:?th0?,?tiketnum?=?4?do?some?thing
thread:?th0?,?tiketnum?=?3?do?some?thing
thread:?th0?,?tiketnum?=?2?do?some?thing
thread:?th0?,?tiketnum?=?1?do?some?thing
thread:?th0?,?tiketnum?=?0?do?some?thing
thread:?th0?,?tiketnum?=?-1?do?some?thing
添加回答
舉報(bào)