}
}
class Test extends Thread
{
public static void main(String[] args)
{
Test t1 = new Test() ;
Test t2 = new Test() ;
t1.start() ;
t2.start() ;
}
public void run()
{
for(int i=0;i<3;i++)
CAdd.add(100) ;
}
}
死锁问题:
程序清单:Deadlock.java
class A
{
synchronized void foo(B b)
{
String name=Thread.currentThread().getName();
System.out.println(name+ " entered A.foo ");
try
{
Thread.sleep(1000);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
System.out.println(name+ " trying to call B.last()");
b.last();
}
synchronized void last()
{
System.out.println("inside A.last");
}
}
class B
{
synchronized void bar(A a)
{
String name=Thread.currentThread().getName();
System.out.println(name + " entered B.bar");
try
{
Thread.sleep(1000);
9
7
3
11
12
13
14
15
16
17
18
19
20
4
8
: