- class Test implements Runnable
- {
- private boolean flag;
- Test(boolean flag)
- {
- this.flag=flag;
- }
- public void run()
- {
- if(flag)
- {
- synchronized(new Mylock())
- {
- System.out.println("if..locka");
- synchronized(new Mylock())
- {
- System.out.println("else..lockb");
- }
- }
- }
- else
- {
- synchronized(new Mylock())
- {
- System.out.println("else..lockb");
- synchronized(new Mylock())
- {
- System.out.println("if..locka");
- }
- }
- }
- }
- }
- class Mylock
- {
- Mylock locka=new Mylock();
- Mylock lockb=new Mylock();
- }
复制代码
1.运行的时候提示
Mylock locka=new Mylock();
Mylock lockb=new Mylock();这里面有问题?
2.synchronized(对象)对象我放new Mylock() 难道不对吗?
3.我在Myclock里面用静态的时候 (对象)直接放Mylock.locka 就没事,为什么不能直接放locka
希望大侠把我这3个问题依次解决了 更多0
|
|