线程Lock的问题
public class LockDemo
{
public static void main(String[] args)
{
LockDemo lo = new LockDemo();
// lo.increment();
A a = new A();
Thread t = new Thread(a,"aa");
Thread t1 = new Thread(a,"bb");
Thread t2 = new Thread(a,"cc");
t.start();
t1.start();
t2.start();
}
}
class A implements Runnable
{
private ReentrantLock rlock = new ReentrantLock();
int i = 100;
public void run()
{
aa();
}
private void aa()
{
try
{
rlock.lock();
while (i > 0)
{
//synchronized (this)
{
System.out.println("i=" + i + Thread.currentThread().getName());
i--;
}
}
} finally
{
rlock.unlock();
}
}
}
为什么用Lock机制时总是一个线程执行该方法呢?