原文地址 http://topic.csdn.net/u/20080710/19/f61cb4db-ddff-4457-a26a-4ea578b0cc6c.html?87447500 http://www.java2000.net/viewthread.jsp?tid=7085 提问:[tteesstt] public class MyTest { public static void main(String[] args) throws Exception { new TestThread()
方法一:动态同步锁 class Demo_thread implements Runnable{ public static int sum = 0; public synchronized void add(){//同步锁,为动态方法 for(int i=0;i<5000;i++){ sum = sum + 1; } } public void run(){ add(); } } 动态同步锁适用于Runnable类中不适用与Thread类,因为其锁的对象为当前实例对象,一个Thread类只能跑