[jboss-user] [Remoting] - LeasePinger error after Timer thread death + fix (happens in

fatbatman do-not-reply at jboss.com
Fri Nov 2 06:46:21 EDT 2007


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);
  |       
  |       try{
  |     	  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)
  |       {
  |          TimerUtil.init();
  |       }
  |       
  |       if (task instanceof StoppableTimerTask)
  |       {
  |          stoppableTasks.add(task);
  |       }
  | 
  |       //schedule at fixed delay (not rate)
  |       try{
  |     	  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");
  |     	  init();
  |       } 
  |    }


Java 1.6.0_03
JBossRemoting remoting_2_2_2_SP2

regards

James

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4101225#4101225

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4101225



More information about the jboss-user mailing list