Thread 控制资源实例

来源:互联网 发布:java 学web 还是安卓 编辑:程序博客网 时间:2024/05/16 00:30
package com.wanju.project001.zonghe.test;import java.util.ArrayList;import java.util.List;public class TestThread {public static List aListSetTest=new ArrayList();public static void main(String[] args) {TestThread testThread = new TestThread();testThread.testThread();}public void testThread(){aListSetTest.add("eeeeee");new Thread(new T()).start();try {Thread.sleep(3000);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}new Thread(new T()).start();}}class T implements Runnable{@Overridepublic void run() {synchronized (TestThread.aListSetTest) {test(this);}}public  void test(Runnable t){while(true){try {Thread.sleep(1000);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}System.out.println("t"+t.toString());}}}
<pre name="code" class="html">tcom.wanju.project001.zonghe.test.T@1cc2ea3ftcom.wanju.project001.zonghe.test.T@1cc2ea3ftcom.wanju.project001.zonghe.test.T@1cc2ea3ftcom.wanju.project001.zonghe.test.T@1cc2ea3ftcom.wanju.project001.zonghe.test.T@1cc2ea3ftcom.wanju.project001.zonghe.test.T@1cc2ea3ftcom.wanju.project001.zonghe.test.T@1cc2ea3ftcom.wanju.project001.zonghe.test.T@1cc2ea3ftcom.wanju.project001.zonghe.test.T@1cc2ea3f



0 0
原创粉丝点击