gpt4 book ai didi

java - 错误 EJB 计时器服务不可用。应用定时器不会被删除

转载 作者:太空宇宙 更新时间:2023-11-04 13:17:15 25 4
gpt4 key购买 nike

我创建了无状态bean,它具有带有@Schedule注释的方法。我在 servlet 中创建我的 bean 实例。 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());
}

}
}

我的 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);

结果我得到错误:

cannot Deploy Lesson32 deploy is failing=Error occurred during deployment: Exception while loading the app: EJB Timer Service is not available. Please see server.log for more details.

错误代码:

[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

我添加属性,如所写http://docs.oracle.com/cd/E18930_01/html/821-2434/ggrvi.html#glhnl一切都没有改变。

最佳答案

这很奇怪。由于您的 EJB 似乎是正确的,并且 glassfish 尝试启动您的计时器方法,但抛出了更一般的异常,因此我认为 glassfish 的配置不正确。

关于java - 错误 EJB 计时器服务不可用。应用定时器不会被删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33442933/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com