1.死锁
package com.java.learnling.test;
public class TestPage221 {
volatile static int test1 = 0;
public static void main(String[] args) {
// TODO Auto-generated method stub
TestPage221 page221 = new TestPage221();
Thread t1 = page221.new TestThread("test1");
TestThread t2 = page221.new TestThread("Test2");
t1.start();
t2.start();
}
class TestThread extends Thread{
public TestThread(String n){
super(n);
}
}
public void run (){
synchronized (TestPage221.class) {
for (int i = 0;i<100000;i++){
int oderNumber = TestPage221.test1;
System.out.println(oderNumber);
TestPage221.test1++;
int newNumber = TestPage221.test1;
System.out.println(newNumber);
if(newNumber != oderNumber){
System.out.println("found");
}
}
}
}
}
2.没有new一个 TestPage221的类对象是不能够直接对类中的内部类进行创建对象
必须先创建外部类的对象再对内部类.调用,来new 一个对象(TestThread());
Multiple markers at this line
- No enclosing instance of type TestPage221 is accessible. Must
qualify the allocation with an enclosing instance of type TestPage221 (e.g.
x.new A() where x is an instance of TestPage221).
- The value of the local variable t1 is not used