62,566
社区成员




/**
* @author Administrator
*
*/
public class ThreadTest implements Runnable {
Test test;
private int j = 1;
public Test getTest() {
return test;
}
public void setTest(Test test) {
this.test = test;
}
public ThreadTest(int j) {
this.j = j;
}
public void run() {
test=Test.getTest();
test.test1(j);
test.test2(j);
test.test3(j);
test.test4(j);
}
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
new Thread(new ThreadTest(i)).start();
}
}
}
class Test {
private static Test test = null;
private Test() {
}
public static Test getTest() {
if (test == null) {
return new Test();
}
return test;
}
public synchronized void test1(int i) {
System.out.println("is test1 Thread =" + i);
}
public synchronized void test2(int i) {
System.out.println("is test2 Thread =" + i);
}
public synchronized void test3(int i) {
System.out.println("is test3 Thread =" + i);
}
public void test4(int i) {
System.out.println("is test4 Thread =" + i);
}
}