2016-10-17 14 views
0

weblogic 10.3.4.0(ejb 3.0)でアプリケーションを停止すると、EJBステートレスのpredestroy faseでタイマをクリーンにします。アプリケーション停止時のタイマキャンセルEJB 3.0

が、WebLogic、このメッセージを上げる

java.lang.IllegalStateException: [EJB:010193]Illegal call to EJBContext method. The bean is in "null" state. It cannot perform 'getting the Timer Service' action(s). Refer to the EJB specification for more details. 

マイpreDestroy方法は

@Resource 
private TimerService timerService; 

@PreDestroy 
public void stopMyTimers() { 
    if(timerService!=null){ 
     for(Timer timer : timerService.getTimers()) { 
      if(timer!=null) timer.cancel(); 
     } 
    } 
}  

Beanが "ヌル" 状態でない場合PreDestroyの前に何かが存在するのですか?

アプリケーションを停止すると、タイマーをキャンセルする方法はありますか?

@javax.ejb.Singleton 
// you might need @javax.ejb.Startup as well 
public class ShutdownController { 

    @EJB 
    private YourEjbWithTimers ejbWithTimers; 

    @PreDestroy 
    void shutdown() { 
     ejbWithTimers.stopMyTimers(); 
    } 

} 

をしてまで、あなたのstopMyTimers方法を変更します:

+0

それは '@のPostConstruct'方法 –

+0

しかし、顧客に起動時にそれらをキャンセルする方が簡単ですアプリケーションが停止したときにキャンセルしたい – Kaltresian

答えて

0

次のようなものを追加することで動作するはずです

 // no annotation 
     public void stopMyTimers() { 
      // null tests not needed 
      // - if something is null then it's broken 
      for(Timer timer : timerService.getTimers()) { 
       timer.cancel(); 
      } 
     }  
関連する問題