0

Currently we are using java.util.concurrent.ExecutorService, java.util.concurrent.Future, java.util.concurrent.Callable to run cron jobs daily. Here our task is grabbing contacts from Gmail java api. We want to implement cron jobs with spring framework. please let me know how?

Thanks in advance..

Harinath
  • 105
  • 1
  • 4
  • 12
  • 1
    Possible duplicate of [How to create a Java cron job](http://stackoverflow.com/questions/22163662/how-to-create-a-java-cron-job) – Raman Shrivastava Jan 12 '16 at 12:48
  • Quatz with Spring is what you are looking for I guess. Refer [this](http://www.mkyong.com/spring/spring-quartz-scheduler-example/) – M4ver1k Jan 12 '16 at 12:52
  • @Raman Shrivastava but i am looking cron jobs with spring framework. thanks... – Harinath Jan 12 '16 at 12:53

2 Answers2

1

For running the process at scheduled time, you can use any of the expression (unix cron expression or fixed delay/rate) with spring framework's Scheduled annotation.

public class DemoScheduleCron
{
    @Scheduled(cron="*/10 * * * * ?")
    //@Scheduled(fixedDelay = 10000)
    //@Scheduled(fixedRate = 10000)
    public void method1()
    {
        System.out.println("This method executs for every 10 seconds");
    }
}

To implement grabbing contacts from Gmail api, you can use spring Quartz / scheduler which is explained here.

Small snippet of configuring concurrency from above docs:

<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
    <property name="corePoolSize" value="5" />
    <property name="maxPoolSize" value="10" />
    <property name="queueCapacity" value="25" />
</bean>

<bean id="taskExecutorExample" class="TaskExecutorExample">
    <constructor-arg ref="taskExecutor" />
</bean>
NamingException
  • 2,388
  • 1
  • 19
  • 41
0

Spring batch + cron

please see the below link: [1]http://www.mkyong.com/spring-batch/spring-batch-and-spring-taskscheduler-example/

snalubo
  • 85
  • 7
  • 2
    Welcome to SO. Please provide your answer with some context; link-only answers are hard to search. See http://stackoverflow.com/help/how-to-answer – Uwe Allner Jan 12 '16 at 13:10