java quartz scheduler fire a new job immediately

user590586 picture user590586 · Mar 27, 2012 · Viewed 56.2k times · Source

Is it possible to crate a job that will trigger immediately ? when i want the job to be triggres now i builed a cron expression string with the current date and time - i think it's too complicated, is there another way to trigger the job immediately ?

Thank's In Advance.

Answer

Rohit Bansal picture Rohit Bansal · Mar 28, 2012

Yeah, use the following Trigger to immediately fire your job instead of waiting upon the Cron Expressions.

    String jobName = ""; // Your Job Name
    String groupName = ""; // Your Job Group
    Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity(jobName, groupName)
                .startNow()
                .build();