📜  如何在java代码示例中使方法线程安全

📅  最后修改于: 2022-03-11 14:52:07.513000             🧑  作者: Mango

代码示例1
class MyCounter {
    private static int counter = 0;
 
    public static synchronized int getCount() {
        return counter++;
    }
}