在需要同步的方法的方法签名中加上 synchronized关键字使用synchronized关键字对需要进行同步的代码块进行同步使用java.util.concurrent.lock包中Lock对象(JDK1.8)