package lesson07;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class ThreadTest implements Runnable{
int count=0;
@Override
public void run() {
Lock lock=new ReentrantLock(true);
//synchronized(ThreadTest.class){
while(true)
{
lock.lock();
if(count<=10)
{
try{
Thread.sleep(100);
}catch(Exception e)
{
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName()+":"+count++);
}
lock.unlock();
}
//}
}
public static void main(String[] args) {
ThreadTest T=new ThreadTest();
Thread T1=new Thread(T);
Thread T2=new Thread(T);
T1.setName("Thread1");
T2.setName("Thread2");
T1.start();
T2.start();
}
}