class A extends Thread {
ThreadDemo demo;
public A(ThreadDemo td) {
demo = td;
}
public void run() {
demo.doSomething();
}
}
public class ThreadDemo {
int count = 1;
public synchronized void doSomething() {
for (int i = 0; i < 10; i++)
System.out.println(count++);
}
public static void main(String[] args) {
ThreadDemo demo = new ThreadDemo();
A a1 = new A(demo);
A a2 = new A(demo);
a1.start();
a2.start();
}
}
1.想知道这段代码中这个构造函数的需要。并解释演示参考如何在 A 类中工作
ps:我是这个概念的新手,所以请帮助我提供你宝贵的答案!提前谢谢!