鍍金池/ 問答/Java  網(wǎng)絡(luò)安全/ static對象在多線程環(huán)境下是否會有同步問題

static對象在多線程環(huán)境下是否會有同步問題

代碼中有一個static的Timer類對象,100個用戶同時請求該方法,使用這個timer對象,用schedlue方法將timerTask任務(wù)提交到這個timer上(也就是說,多線程訪問這個static的timer對象),這時候,如果timer沒有加鎖,會有同步問題嗎?
日志中,timer.schedule方法頻繁報錯,我不確定是什么引起的

回答
編輯回答
挽歌

This class is thread-safe: multiple threads can share a single Timer object without the need for external synchronization.

https://docs.oracle.com/javas...

2018年5月6日 00:48
編輯回答
陪我終

Timer對象不需要同步,本身是線程安全的。

2017年9月19日 15:25