Hi , I have situation like this: I have two classes Class1 and Class 2; Class1 { public Class1(){ } private class insideclass1{ //methods } } Class2 { private class mythread extends Thread{ public void run(){ //logic } } In Class2 , i create threads of type mythread and start them. These threads (logic) access synchronized methods in Class1 and should wait for notify() from class1. My problem : In order to access methods in Class1, i have declared them to be synchronized and static But i cannot call wait() and notify()and these are non-static methods. How can over come this problem Any help is apprciated . Please help. Thanks Praveen.
Peter den Haan
author
Ranch Hand
Joined: Apr 20, 2000
Posts: 3252
posted
0
Static synchronized methods acquire a lock on the class object, so you can call Class1.class.wait() and so forth. Whether this is a good design is another matter. Can't you pass a Class1 instance you can use, or alternatively, can't you turn Class1 into a Singleton? In a pinch, you could also consider a separate monitor object (an Object created just to synchronize on). - Peter