title: schedule a message driven bean to access a queue during certain times?
body: <p>1) <strong>Can you schedule a message driven bean to access a queue only at certain times?</strong> </p>
  
  <p>For example, user has two contact options - between 9am-5pm and 5pm-10pm. I'd like to have two MDB one that is only active from 9am-5pm and the other at 3pm-10pm. </p>
  
  <p>Both queues have messages sent to them throughout the day but I'd only like to process them at the specific times. </p>
  
  <p>Ideally <strong>@Schedule</strong> would work but unfortunately it doesn't. </p>
  
  <p>Using Glassfish 3.1.2 and ActiveMQ 5.5.1 but I'm pretty sure it's not an implementation specific question.</p>
  
  <p><strong>Edit 1</strong></p>
  
  <p>Code</p>
  
  <pre><code>@MessageDriven(
      activationConfig = {
          @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
          @ActivationConfigProperty(propertyName = "destination", propertyValue = "jms/queue/amqmsg")
  })
  public class ExampleMessageBean implements MessageListener {
  
  @Schedule(second="*", minute="*", hour="9-17", persistent = false)
  public void onMessage(Message message) {
      try {
          System.out.println("We've received a message: " + message.getJMSMessageID());
  
          System.out.println("\n\n Message\n\n" + message);
  
      } catch (JMSException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Getting error on deployment. I don't think it's possible for @Schedule to be used in this way. Can anyone confirm?</p>
  
  <pre><code>SEVERE: Exception while invoking class org.glassfish.ejb.startup.EjbDeployer load method java.lang.RuntimeException: EJB Container initialization error
  at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:242)
  at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:299)
  at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:105)
  at org.glassfish.internal.data.ModuleInfo.load(ModuleInfo.java:186)
  at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:264)
  at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:460)
  at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
  at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
  at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
  at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
  at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
  at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
  at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
  at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
  at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
  at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
  at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
  at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
  at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
  at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
  at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
  at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
  at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
  at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
  at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
  at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
  at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
  at java.lang.Thread.run(Thread.java:662)
   Caused by: javax.ejb.EJBException: Invalid @Timeout or @Schedule signature for: public void com.name.mdb.ExampleMessageBean.onMessage(javax.jms.Message) @Timeout or @Schedule method must return void and be a no-arg method or take a single javax.ejb.Timer param
  at com.sun.ejb.containers.BaseContainer.processEjbTimeoutMethod(BaseContainer.java:2219)
  at com.sun.ejb.containers.BaseContainer.&lt;init&gt;(BaseContainer.java:743)
  at com.sun.ejb.containers.MessageBeanContainer.&lt;init&gt;(MessageBeanContainer.java:142)
  at com.sun.ejb.containers.ContainerFactoryImpl.createContainer(ContainerFactoryImpl.java:121)
  at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:230)
  ... 33 more
  
     SEVERE: Exception while loading the app
     INFO: No timers to be deleted for id: 87558812344647680
     SEVERE: Exception while loading the app : EJB Container initialization error
     javax.ejb.EJBException: Invalid @Timeout or @Schedule signature for: public void com.test.mdb.ExampleMessageBean.onMessage(javax.jms.Message) @Timeout or @Schedule method must return void and be a no-arg method or take a single javax.ejb.Timer param
  at com.sun.ejb.containers.BaseContainer.processEjbTimeoutMethod(BaseContainer.java:2219)
  at com.sun.ejb.containers.BaseContainer.&lt;init&gt;(BaseContainer.java:743)
  at com.sun.ejb.containers.MessageBeanContainer.&lt;init&gt;(MessageBeanContainer.java:142)
  at com.sun.ejb.containers.ContainerFactoryImpl.createContainer(ContainerFactoryImpl.java:121)
  at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:230)
  at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:299)
  at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:105)
  at org.glassfish.internal.data.ModuleInfo.load(ModuleInfo.java:186)
  at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:264)
  at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:460)
  at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
  at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
  at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
  at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
  at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
  at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
  at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
  at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
  at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
  at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
  at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
  at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
  at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
  at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
  at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
  at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
  at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
  at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
  at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
  at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
  at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
  at java.lang.Thread.run(Thread.java:662)
  </code></pre>