Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch so that CronTriggerBean can take a start delay [SPR-5727] #10397

Closed
spring-projects-issues opened this issue May 7, 2009 · 3 comments
Closed
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Robin Bramley opened SPR-5727 and commented

The SimpleTriggerBean supports a start delay, this patch adds the same feature to the CronTriggerBean so that you can defer the execution (e.g. to allow the system to stabilise at start-up).


Affects: 2.5.6, 3.0 M3

Attachments:

Issue Links:

Referenced from: commits 90652bf

@spring-projects-issues
Copy link
Collaborator Author

Robin Bramley commented

Can be tested with e.g.:

@Test
public void testAfterPropertiesSet() throws Exception {
    Date date0 = new Date();
    
    CronTriggerBean trigger0 = new CronTriggerBean();
    trigger0.setBeanName("beanName");
    trigger0.setStartDelay(0L);
    trigger0.afterPropertiesSet();
    assertNotNull(trigger0.getStartTime());
    
    // date compareTo: -1 < arg ; 0 = arg; 1 > arg
    Date date1 = trigger0.getStartTime();
    assertTrue(date0.compareTo(date1) >= 0);
}

@Test
public void testAfterPropertiesSetDelayedStart() throws Exception {
    Date date0 = new Date();
    CronTriggerBean trigger1 = new CronTriggerBean();
    trigger1.setBeanName("beanName");
    trigger1.setStartDelay(180000L);
    trigger1.afterPropertiesSet();
    assertNotNull(trigger1.getStartTime());
    // date compareTo: -1 < arg ; 0 = arg; 1 > arg
    Date date2 = trigger1.getStartTime();
    assertEquals(-1, date0.compareTo(date2));
}

@spring-projects-issues
Copy link
Collaborator Author

John Allen commented

For the use case mentioned, delay ing execution to allow the system to stabilise, the scheduler supports an overall startup delay.

@spring-projects-issues
Copy link
Collaborator Author

Robin Bramley commented

You're right that the SchedulerFactoryBean has a startupDelay property too (though specified in seconds) which would be a better fit for the example given above. This Jira/patch allows finer-grained delay on individual cron triggers as per the SimpleTriggerBean (could be viewed as being slightly against the cron 'fire at this point in time' grain)...

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0 RC1 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant