【发布时间】:2014-08-23 20:07:53
【问题描述】:
class A implements Runnable //Thread class
{
public void run()
{
read();
}
public synchronized void read()
{
for(int i= 0 ; i< 7 ;i++)
System.out.println(Thread.currentThread().getName() + " " + i);
}
}
public class Main
{
public static void main(String[] args)
{
Thread t = new Thread(new A());
t.setName("t1");
Thread c = new Thread(new A());
c.setName("t2");
t.start();
c.start();
}
输出:
【问题讨论】:
-
你在两个不同的线程上调用方法
标签: java multithreading runnable synchronized