Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » ServerJob doesn't wait for delay before to reschedule
ServerJob doesn't wait for delay before to reschedule [message #983214] Tue, 13 November 2012 19:27 Go to next message
Boy D'Poy is currently offline Boy D'Poy
Messages: 56
Registered: October 2011
Member
i have this snippet:


==========
final long delay = 10000L;
final String name = "name";
new ServerJob(name, ServerJob.getCurrentSession(ServerSession.class)) {

@Override
protected IStatus runTransaction(final IProgressMonitor monitor) throws Exception {

try {
//
// exceptionalCode();
//
}
catch (final Exception e) {
this.schedule(delay);
return Status.CANCEL_STATUS;
}
this.schedule();
return Status.OK_STATUS;
}
}.schedule();
==========

I would like the job to wait for 10 seconds before the next attempt if the exceptionalCode throws an exception, but the expected behaviour is not matched: the job restarts immediately.

What dit I did wrong?

Thanks.




Once You Go Scout, You Never Come Out!
icon14.gif  Re: ServerJob doesn't wait for delay before to reschedule [message #986679 is a reply to message #983214] Wed, 21 November 2012 11:01 Go to previous messageGo to next message
Ken Lee is currently offline Ken Lee
Messages: 97
Registered: March 2012
Member
Hi,

If schedule(delay) is executed in the catch block, the call to this.schedule(delay) is returned immediately, i.e. schedule(delay) is non-blocking! The ServerJob is queued but will be rescheduled after the time defined in delay which corresponds with the JavaDoc in the class org.eclipse.core.runtime.jobs

* If this job is currently running, it will be rescheduled with the specified
* delay as soon as it finishes.  If this method is called multiple times
* while the job is running, the job will still only be rescheduled once,
* with the most recent delay value that was provided.


In your example with console ouputs:

  @Override
  public void rescheduleServerJobWithDelay(final boolean throwException) throws ProcessingException {
    final long delay = 10000L;
    final String name = "name";
    new ServerJob(name, ServerJob.getCurrentSession(ServerSession.class)) {
      @Override
      protected IStatus runTransaction(final IProgressMonitor monitor) throws Exception {
        try {
          System.out.println("running transaction in try block");
          if (throwException) {
            throw new ProcessingException("throws processing exception");
          }
        }
        catch (final Exception e) {
          System.out.println("catched exception. rescheduling in 10sec...");
          long start = System.currentTimeMillis();
          this.schedule(delay);
          long end = System.currentTimeMillis() - start;
          System.out.println("catched exception. returned back from schedule call after " + end + "sec");
          return Status.CANCEL_STATUS;
        }
        System.out.println("no exception. rescheduling immediately ...");
        long start = System.currentTimeMillis();
        this.schedule();
        long end = System.currentTimeMillis() - start;
        System.out.println("no exception. returned back from schedule call after " + end + "sec");
        return Status.OK_STATUS;
      }
    }.schedule();
  }


Passing throwException=true will lead to the output:

running transaction in try block
catched exception. rescheduling in 10sec...
catched exception. returned back from schedule call after 0sec
[after 10sec]
running transaction in try block
catched exception. rescheduling in 10sec...
catched exception. returned back from schedule call after 0sec

BTW: Do you really need to reschedule the ServerJob in the non-exception case? Wouldn't it be possible to encapsulate your ServerJob code in a while-block?














Re: ServerJob doesn't wait for delay before to reschedule [message #989148 is a reply to message #986679] Tue, 04 December 2012 20:24 Go to previous message
Boy D'Poy is currently offline Boy D'Poy
Messages: 56
Registered: October 2011
Member
Hi!
Sorry for my late reply.
I solved the problem in a similar way you suggest:
ServerJob + while-loop Wink

Thank you!


Once You Go Scout, You Never Come Out!
Previous Topic:Scout RT model
Next Topic:Deleting Rows in TableField not calling store
Goto Forum:
  


Current Time: Thu Oct 23 17:15:25 GMT 2014

Powered by FUDForum. Page generated in 0.05262 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software