Hi,

     I have developed a web application using struts 2. In my struts 2
action class i am calling the service layer and written the synchronization
code as below in the service layer. Does this really gets synchronized? Is
there any problem in my synchronization code?



*The following is my action class:-*



public class AbcAction extends ActionSupport{

     private AbcService ser=new AbcServiceImpl(); //AbcService is an
Interface



     public String execute(){

     ser.createNewRegistration();

     return "SUCCESS";

     }



}



*The following is my service Impl class:-*



public class AbcServiceImpl implements AbcService{

private AbcDao dao=new AbcDaoImpl();



public void  .createNewRegistration(){

synchronized(AbcServiceImpl.class){

dao.createTheRegistration();

}

}

}



by writing the above code i assume that no two threads can run the
"dao.createTheRegistration()"
method at the same time. but when we analyze the logs i observed this is
not happening. Two threads are able to execute the method at the same time.
What is the problem in my code?



*Thanks and Regards,*
Muralidhar Yaragalla.

*http://yaragalla.blogspot.in/ <http://yaragalla.blogspot.in/>*

Reply via email to