package com.homework; public class MyRunnable3 implements Runnable{ public static int sum = 0; public boolean flag = true; public Object obj = new Object(); @Override public void run() { for(int i=0;i<3;i++){ setSum(); } } public static synchronized void setSum(){//靜態同步方法。---同步鎖爲MyRunnable3.class sum+=100; try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } System.out .println(Thread.currentThread().getName() + "存了100元,現有" + sum+":同步方法"); } }