为什么说找不到符号
本人新手,最近在学习线程,运行下面一段死锁的代码报错
OUTPUT:
Thread_1.java:40: 错误: 找不到符号
synchronized(MyLock.looka)
^
符号: 变量 looka
位置: 类 MyLock
贴Code 谢谢帮忙看看
class My_Mutex implements Runnable
{
private boolean flag;
My_Mutex(boolean flag)
{
this.flag = flag;
}
public void run()
{
if(flag)
{
synchronized(MyLock.looka)
{
System.out.println(" i get the lock_1");
synchronized(MyLock.lookb)
{
System.out.println(" i get the lock_2");
}
}
}
else
{
synchronized(MyLock.lockb)
{
System.out.println(" i get the lock_2 flaxe");
synchronized(MyLock.looka)
{
System.out.println(" i get the lock_1 flase");
}
}
}
}
}
class MyLock
{
public static final Object locka = new Object();
public static final Object lcckb = new Object();
}
class Thread_1
{
public static void main(String[] args)
{
System.out.println("Hello World!");
// Single a = new Single();
My_Mutex tmp_mutex_1 = new My_Mutex(true);
My_Mutex tmp_mutex_2 = new My_Mutex(false);
Thread t1 = new Thread(tmp_mutex_1);
Thread t2 = new Thread(tmp_mutex_2);
t1.start();
t2.start();
}
}
------解决方案--------------------synchronized(MyLock.
looka)
public static final Object
locka = new Object();
public static final Object
lcckb = new Object();
你用工具啊,