3 Replies Latest reply on Apr 2, 2009 3:00 AM by Ron Sigal

    LeasePinger error after Timer thread death + fix (happens in

    fatbatman Novice

      We're using remoting within a applet based application.

      If the user navigates away from the page the browser plugin kills off various threads related to applet (I'm not 100% sure how it decides what is killed and what isn't). The JVM continues running.
      If the user returns to the applet, remoting will fail if enableLease is true.

      The problem is that in org.jboss.remoting.LeasePinger a static Timer timer is created once when each class is first used up. If these threads gets killed (such as by the browser plugin) all future requests to scheduled a task will fail.

      The solution we used if a quick check to see that the tasks have been scheduled correctly, if not we create a new Timer.

      For org.jboss.remoting.LeasePinger.java;

      public void startPing()
       if(trace) { log.trace(this + " starting lease timer with ping period of " + pingPeriod); }
       timerTask = new LeaseTimerTask(this);
       log("Hacked LeasePinger v0.1");
       timer.schedule(timerTask, pingPeriod, pingPeriod);
       }catch(java.lang.IllegalStateException e){
       log("LeasePinger.timer was canceled" +e.getMessage());
       log("Creating new Timer");
       timer = new Timer(true);
       timer.schedule(timerTask, pingPeriod, pingPeriod);

      Note something similar can happen in org.jboss.remoting.util.TimerUtil
      if the user doesn't manually call TimerUtil.destroy(), a similar fix is;

      public static synchronized void schedule(TimerTask task, long period)
       if (TimerUtil.timer == null)
       if (task instanceof StoppableTimerTask)
       //schedule at fixed delay (not rate)
       log("Hacked TimerUtil v0.1");
       TimerUtil.timer.schedule(task, period, period);
       }catch(java.lang.IllegalStateException e){
       log("TimerUtil.timer was canceled" +e.getMessage());
       log("Creating new Timer");

      Java 1.6.0_03
      JBossRemoting remoting_2_2_2_SP2



        • 1. Re: LeasePinger error after Timer thread death + fix (happen
          Ron Sigal Master

          Hi James,

          Yes, when all the TimerTasks have shut down, the Timer shuts down as well. I was bitten by this same problem a while back in the bisocket transport, and I didn't notice it existed elsewhere as well. I've created JIRA issue JBREM-851 "In LeasePinger and TimerUtil replace Timer if it has shut down" (http://jira.jboss.com/jira/browse/JBREM-851) and scheduled it for Remoting 2.4.0.

          Thanks for bringing this problem to my attention.


          • 2. Re: LeasePinger error after Timer thread death + fix (happen
            fatbatman Novice

            I'm not convinced the issue within LeasePinger is resolved as when using 2_5_0_SP2 I get;

            java.lang.RuntimeException: Error setting up client lease upon performing connect.
             at org.jboss.remoting.Client.connect(Client.java:1603)
             at org.jboss.remoting.Client.connect(Client.java:498)
             at com.joyplay.client.net.jbossremoting.JadeRemotingClient.createServletClient(JadeRemotingClient.java:309)
             at com.joyplay.client.connection.MusConnection.login(MusConnection.java:373)
             at com.joyplay.client.connection.MusConnection.login(MusConnection.java:228)
             at com.joyplay.client.games.lobby.LobbyMessageHandler$2.run(LobbyMessageHandler.java:164)
             at java.lang.Thread.run(Unknown Source)
            Caused by: java.lang.Exception: Error setting up client lease
             at org.jboss.remoting.MicroRemoteClientInvoker.establishLease(MicroRemoteClientInvoker.java:484)
             at org.jboss.remoting.Client.setupClientLease(Client.java:1699)
             at org.jboss.remoting.Client.connect(Client.java:1599)
             ... 6 more
            Caused by: java.lang.IllegalStateException: Timer already cancelled.
             at java.util.Timer.sched(Unknown Source)
             at java.util.Timer.schedule(Unknown Source)
             at org.jboss.remoting.LeasePinger.startPing(LeasePinger.java:99)
             at org.jboss.remoting.MicroRemoteClientInvoker.establishLease(MicroRemoteClientInvoker.java:478)

            in the same situation as before.
            I've added my try catch hack back in and all is ok again.


            • 3. Re: LeasePinger error after Timer thread death + fix (happen
              Ron Sigal Master

              Yup: "CLONE [JBREM-851] - In LeasePinger replace Timer if it has shut down" (https://jira.jboss.org/jira/browse/JBREM-1111).

              What was I thinking?