public abstract class Port extends Thread
{
.......里面的代码
}
class Test2
{
public Test2 ()
{
port= null;
}
.......里面的代码
public void setPort(Port port)
{
port = port;
} public Port getPort()
{
return port;
}
Port port;
}
class Test extends Test2
{
synchronized(this) [如果改成synchronized(super.port)有什么区别] {
.......里面的代码
}
}
{
.......里面的代码
}
class Test2
{
public Test2 ()
{
port= null;
}
.......里面的代码
public void setPort(Port port)
{
port = port;
} public Port getPort()
{
return port;
}
Port port;
}
class Test extends Test2
{
synchronized(this) [如果改成synchronized(super.port)有什么区别] {
.......里面的代码
}
}
class Test extends Test2
{
public static void main(String[] args) { thread = new Thread(Test );
thread.start();
}
public void run() { synchronized(this) [如果改成synchronized(super.port)有什么区别] {
.......里面的代码
}
}
}
synchronized(this) 包含了synchronized(super.port)
这个类用的又不是父类的port,synchronized(super.port)没有任何作用
如果这个类用了父类的port,synchronized(super.port)就起作用了