0 Replies Latest reply on Sep 30, 2004 7:57 AM by Alex

    Synchronization method call in my MBean?

    Alex Newbie

      I want blocked exucute some method on my MBean if that method execute allredy. I use in my method doOperation

      synchronized(this)
      {
       //some code......
      }

      For example if Client 1 start remote invocation this method, and after some time Client2 start remote invocation this method, Client2 will wait until invocation from Client1 return result. I write simple MBean for test it.

      public class MyMbean extends org.jboss.system.ServiceMBeanSupport {
      
       String name = "simple";
       public void start() throws java.lang.Exception {
       }
      
       public String getName(){
       return name;
       }
      
       public void stop() {
       }
      
       public void doOperation(String name,long time){
       System.out.println("start operation " + name);
       synchronized(this){
       try{
       Thread.currentThread().sleep(time);
       }
       catch(Exception e){
       e.printStackTrace();
       }
       this.name = name;
       System.out.println("stop operation " + name);
       }
       }
      }


      This exaple work fine.
      Is it right method to solve my problem, or under Jboss i must use another method?