I created a Stateless bean that has a method annotated by @Schedule. I run a bean using a servlet. Bean code:

@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 code:

 @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); } 

}

As a result, it produces the following error: cannot be deployed during deployment: Exception while loading the app: EJB Timer Service is not available. Please see server.log for more details.

Full error code:

  [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 at com.sun.ejb.containers.BaseContainer.startApplication(BaseContainer.java:4009) at org.glassfish.ejb.startup.EjbApplication.start(EjbApplication.java:163) at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122) at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:291) at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:352) at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:500) at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219) at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491) at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:539) at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:535) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAs(Subject.java:356) at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:534) at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:565) at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:557) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAs(Subject.java:356) at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:556) at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1464) at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1300(CommandRunnerImpl.java:109) at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1846) at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1722) at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534) at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224) at org.glassfish.grizzly.http.server.StaticHttpHandlerBase.service(StaticHttpHandlerBase.java:189) at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167) at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206) at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180) at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235) at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200) at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132) at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111) at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536) at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571) at java.lang.Thread.run(Thread.java:745) 

]]

Following the instructions: http://docs.oracle.com/cd/E18930_01/html/821-2434/ggrvi.html#glhnl I created the property com.sun.ejb.timer.ReadDBBeforeTimeout = false in glassfish. And the error remained the same .. Help please, who faced such a problem.

  • Is the timer service itself configured and running? Can help stackoverflow.com/questions/22786424/… - Russtam
  • but how exactly do you need to configure it ?? in admin. I found these tabs in the console, but I don’t have any idea what to change there. I understand you need to change the value in the server-config -> EJB Container -> EJB Timer Service tab in the Timer Datasource field. And in the Resources tab -> JDBC -> JDBC Connection Pools -> __TimerPool I don’t understand what’s all about jdbc, if I don’t have any databases .... - Yura
  • Can anything change and the server settings did not have to? The timer should work right away. And jdbc here, despite the fact that you can configure how the server will store timers (they are persistent, but for some, if not all, you can disable it), if you are not satisfied with the default method. Including can be stored in the database. This is where jdbc appears. - Sergey
  • Well, at first I didn’t change anything, and it didn’t work, then I changed it only in server-config -> EJB Container -> EJB Timer Service tab in the Timer Datasource field entered _TimerPool. And nothing ... - Yura
  • I looked at glassfish 3. Although there is also nothing in the Timer Datasource, but there is a JDBC Connection Pool called __TimerPool. Two underscores in front. In version 3, timers worked without any gestures. - Sergey

1 answer 1

Hello, timers work on the basis of internal JAVADB, check in the control panel: 4848 pool JDBC / JDBC connection pool / __ timerPool pinging if there is an answer. Remove / glassfish4 / glassfish / domains / domain1 / lib / databases / ejbtimer, and remove the error / flagfish4 / glassfish / domains / domain1 / generated / ejb-timer-service-app flag file, restart the server, it should recover