简体   繁体   English

错误EJB计时器服务不可用。 申请计时器不会被删除

[英]Error EJB Timer Service is not available. Timers for application will not be deleted

I created Stateless bean, which has method with @Schedule annotation. 我创建了Stateless bean,它具有带有@Schedule批注的方法。 I create instance of my bean in servlet. 我在servlet中创建bean的实例。 Code of bean: 豆代码:

 @Stateless
 public class StockServerBean {
 private String price=null;
 private ArrayList<String> nasdaqSymbols = new ArrayList<String>();
 private String chooseSymb;
 public String getChooseSymb() {
  return chooseSymb;
}

public void setChooseSymb(String chooseSymb) {
  this.chooseSymb = chooseSymb;
}

public StockServerBean(){
// Define some hard-coded NASDAQ symbols
nasdaqSymbols.add("AAPL");
nasdaqSymbols.add("MSFT");
nasdaqSymbols.add("YHOO");
nasdaqSymbols.add("AMZN");
nasdaqSymbols.add("MOT");
}

@Schedule(second="*",minute="*",hour="18,00-22,00", dayOfWeek="Mon-Sun")
public void getQuote(){
if(nasdaqSymbols.indexOf(chooseSymb.toUpperCase()) != -1) {
// Generate a random price for valid symbols
price = (new Double(Math.random()*100)).toString();
}
Session session = null;
Connection conn = null;
ConnectionFactory factory = null;
try{
    Context jndiC = new InitialContext();
    factory = (ConnectionFactory)jndiC.lookup("MyTestConnectionFactory");
    Queue queue = (Queue)jndiC.lookup("MyJMSTestQueue");

    conn = factory.createConnection();
    conn.start();

    session = conn.createSession(false,Session.AUTO_ACKNOWLEDGE);

    MessageProducer sender = session.createProducer(queue); 
    TextMessage outM = session.createTextMessage(chooseSymb + " : " + price);
    sender.send(outM);
    sender.close();
    System.out.println("Succesfully placed a price of  "  + chooseSymb + " :"+ price);

}catch(JMSException je){
    System.out.println("Error: " + je.getMessage());
}catch(NamingException ne){
    System.out.println("Error: " + ne.getMessage());
    ne.printStackTrace();
}finally{
    try{
        session.close();
        conn.close();

    }catch(Exception e){
        System.out.println("Can't close session/connection :" + e.getMessage());
    }

}
}

Code of my servlet: 我的Servlet代码:

  @WebServlet("/ExecutionServlet")
  public class ExecutionServlet extends HttpServlet {
  private static final long serialVersionUID = 1L;

 /**
  * @see HttpServlet#HttpServlet()
 */
public ExecutionServlet() {
 super();
// TODO Auto-generated constructor stub
 }

 /**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse        response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse    response) throws ServletException, IOException {
// TODO Auto-generated method stub
StockServerBean bean = new StockServerBean();
bean.setChooseSymb("AAPL");
bean.getQuote();
PrintWriter out = response.getWriter();
out.println("Sending price to the queue");

}

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse  response)
 */
    protected void doPost(HttpServletRequest request, HttpServletResponse       response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);

In result I obtain error: 结果我得到错误:

cannot Deploy Lesson32 deploy is failing=Error occurred during deployment: Exception while loading the app: EJB Timer Service is not available. 无法部署Lesson32部署失败=部署期间发生错误:加载应用程序时发生异常:EJB计时器服务不可用。 Please see server.log for more details. 请参阅server.log以获取更多详细信息。

Code of error: 错误代码:

[2015-10-29T21:53:23.581+0200] [glassfish 4.1] [SEVERE] [NCLS-CORE-00026] [javax.enterprise.system.core] [tid: _ThreadID=47 _ThreadName=admin-listener(4)] [timeMillis: 1446148403581] [levelValue: 1000] [[ Exception during lifecycle processing java.lang.RuntimeException: EJB Timer Service is not available [2015-10-29T21:53:23.581 + 0200] [glassfish 4.1] [SeverE] [NCLS-CORE-00026] [javax.enterprise.system.core] [tid:_ThreadID = 47 _ThreadName = admin-listener(4) ] [timeMillis:1446148403581] [levelValue:1000] [[生命周期处理期间的异常java.lang.RuntimeException:EJB计时器服务不可用

I add property, as writed http://docs.oracle.com/cd/E18930_01/html/821-2434/ggrvi.html#glhnl and nothing changed. 我添加了属性,如http://docs.oracle.com/cd/E18930_01/html/821-2434/ggrvi.html#glhnl所写,没有任何更改。

That's strange. 那很奇怪。 As your EJB seems to be correct and glassfish tries to start your timer method but throws a more general exception, I think, glassfish is not correctly configured. 由于您的EJB似乎是正确的,并且glassfish尝试启动您的计时器方法,但引发了更一般的异常,我认为glassfish的配置不正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM