@@ -0,0 +1,2047 @@
+package xm.thread;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0A/**%0A * @author xuming%0A */%0Apublic class SyncDemo %7B%0A    public static void main(String%5B%5D args) %7B%0A        List%3CInteger%3E dataList = new ArrayList%3CInteger%3E();%0A        for (int i = 0; i %3C 30; ++i) %7B%0A            dataList.add(i);%0A        %7D%0A        System.out.println(%22%E6%80%BB%E6%95%B0%E6%8D%AE%E9%9B%86%EF%BC%9A%22 + dataList);%0A        long start = System.currentTimeMillis();%0A        int t = Runtime.getRuntime().availableProcessors();%0A        System.out.println(t);%0A        WorkThread%5B%5D workThreadArray = new WorkThread%5B4%5D;%0A        for (int i = 0; i %3C workThreadArray.length; ++i) %7B%0A            workThreadArray%5Bi%5D = new WorkThread(%22%E7%BA%BF%E7%A8%8B%22 + i, dataList.subList(i * 3, (i + 1) * 3));%0A            workThreadArray%5Bi%5D.start();%0A        %7D%0A        for (WorkThread aWorkThread : workThreadArray) %7B%0A            try %7B%0A                aWorkThread.join();%0A            %7D catch (InterruptedException e) %7B%0A                e.printStackTrace();%0A            %7D%0A        %7D%0A        System.out.println(%22%E7%BB%93%E6%9E%9C%E6%B1%87%E6%80%BB%EF%BC%9A%22 + dataList);%0A        System.out.println(%22%E8%80%97%E6%97%B6%EF%BC%9A%22 + (System.currentTimeMillis() - start));%0A    %7D%0A%0A    static class WorkThread extends Thread %7B%0A        private List%3CInteger%3E workDataList;%0A%0A        WorkThread(String name, List%3CInteger%3E workDataList) %7B%0A            super(name);%0A            this.workDataList = workDataList;%0A        %7D%0A%0A        @Override%0A        public void run() %7B%0A            System.out.println(getName() + %22%E5%BC%80%E5%A7%8B%E5%A4%84%E7%90%86%22 + workDataList);%0A            for (int i = 0; i %3C workDataList.size(); ++i) %7B%0A                workDataList.set(i, workDataList.get(i) + 1);%0A                try %7B%0A                    Thread.sleep(1000);%0A                %7D catch (InterruptedException e) %7B%0A                    e.printStackTrace();%0A                %7D%0A            %7D%0A            System.out.println(getName() + %22%E5%A4%84%E7%90%86%E5%AE%8C%E6%AF%95%22 + workDataList);%0A        %7D%0A%0A        public List%3CInteger%3E getResult() %7B%0A            return workDataList;%0A        %7D%0A    %7D%0A%7D%0A%0A// thread:2 time: 3025%0A// thread:3 time: 3013%0A// thread:4 time: 3012%0A// thread:5 time: 3020%0A// thread:10 time: 3238

add sync thread demo。xuming 20161209