title: Obtain object level concurrency - JAVA
body: <p>I am new to multi-threading and need a little help in object level locking. Thanks in advance.</p>
  
  <p>I have two classes say Person and Attendance and 2 methods (setAttendance, getAttendance) in each of the classes such that method of Class Person calls the specific method of Class Attendance. Both the methods in class Attendance are synchronized.
  I want to obtain concurrency in such a way that if method 1 is in progress, method 2 cannot be called by the same user. I want to obtain object level locking and want to  create the object on session level, i.e. obtain concurrency on session level(i.e. methods are locked for 1 user but if the web application is accessed by some other user, he can access the method if it was not locked by him)
  Here is the code snippet:</p>
  
  <pre><code>class Person{
  
      //method 1
      public void setAttendance(){
          //call setAttendance method of class Ateendance
       }
  
       //method 2
      public void getAttendance(){
          //call getAttendance method of class Ateendance
       }
  }
  
  // methods of class Attendance are called from Person class
  
  Class Attendance{
  
     // method 1
     void synchronized setAttendance(String str){
  
      }
  
     // method 2
     String synchronized getAttendance(){
       return "";
     }
  }
  </code></pre>