title: How to reschedule a Liferay task dynamically?
body: <p>I have created a portlet (extending <code>MVCPortlet</code>), with a class that extends <code>MessageListener</code> to perform certain automated tasks. Let's call this class <code>SessionCollector</code>.</p>
  
  <p>The file <code>liferay-portlet.xml</code> contains the following configuration snippet:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;scheduler-entry&gt;
      &lt;scheduler-event-listener-class&gt;
          com.myportal.scheduler.SessionCollector
      &lt;/scheduler-event-listener-class&gt;
  
      &lt;trigger&gt;
          &lt;simple&gt;
              &lt;simple-trigger-value&gt;10&lt;/simple-trigger-value&gt;
              &lt;time-unit&gt;minute&lt;/time-unit&gt;
          &lt;/simple&gt;
      &lt;/trigger&gt;
  &lt;/scheduler-entry&gt;
  </code></pre>
  
  <p>The task is set to start every 10 minutes.</p>
  
  <p>The thing is, in my project, every configuration variable must be in a property file available in the server classpath. Let's say I have a <code>.properties</code> file with the following line:</p>
  
  <pre class="lang-properties prettyprint-override"><code>session.collector.cron.text=0 0/5 * * * ?
  </code></pre>
  
  <p>So, I want to reschedule the task to use that Cron expression, which means the task will be run every 5 minutes.</p>
  
  <p>I've tried to write the rescheduling in the <code>init ( )</code> method of the portlet, but to no avail.</p>
  
  <p>This is the code, with some simplifications:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Override
  public void init ( ) throws PortletException {
      // Reads the contents of the properties file.
      String cronText = getCronText ( );
  
      String jobName = SessionCollector.class.getName ( );
      String jobGroup = SessionColllector.class.getName ( );
  
      // The trigger is set to fire up using the Cron expression.
      Trigger trigger = TriggerFactoryUtil.buildTrigger (
          TriggerType.CRON,
          jobName,
          jobGroup,
          new Date ( ),
          null,
          cronText
      );
  
      // This is the message to fire the rescheduling.
      Message message = new Message ( );
      message.put (SchedulerEngine.MESSAGE_LISTENER_CLASS_NAME, jobName);
      message.put (SchedulerEngine.PORTLET_ID, this.getPortletName ( ));
  
      // And finally, the actual reschedule.
      SchedulerEngineUtil.schedule (
          trigger,
          StorageType.PERSISTED,
          ""
          "liferay/scheduler_dispatch",
          message,
          5
      );
  }
  </code></pre>
  
  <p>I suspect the problem lies in the way I get the portlet id (at least, it could be one of the problems). Anyway, the rescheduling does not throw any exception, but the rescheduling does not take place, nevertheless. The task keeps on running every 10 minutes, not 5.</p>
  
  <p>So, to be clear, is there any way to reschedule the task dynamically in the portlet itself? Notice that the portlet is just deployed, but not added to any page, thus, it lacks any rendering code.</p>
  
  <p>Thanks!</p>
  
  <h2>Update (23/11/2015)</h2>
  
  <p>This question has been proposed as being a duplicate of <a href="https://stackoverflow.com/questions/17926093/h2-sql-grammar-exception">another question</a>, but I think it's fairly unrelated.</p>
  
  <p>My question is related to the mechanisms Liferay uses to schedule/reschedule automated tasks, using Quartz as the underlying scheduler engine, and the other question is related to an H2 Database/Hibernate layer problem, as far as I can tell.</p>