@Schedule Doesnt trigger the Service at a fixed time












0














I am trying to schedule a service from spring-boot at a fixed rate with an initial delay,

After deploying, I was expecting that the read method should be executed after 5 secs and every 10 seconds, but nothing is displayed in the console.
Here is my main application class



@SpringBootApplication
@EnableScheduling
public class ArgusAPIApplication {

@Value("${proxy.host}")
private String proxyHost;
@Value(("${proxy.port}"))
private int proxyPort;
@Value(("${readTimeout}"))
private int readTimeout;
@Value(("${connectTimeout}"))
private int connectTimeout;


public static void main(String args) {
SpringApplication.run(ArgusAPIApplication.class, args);
}

@Bean
public RestTemplate restTemplate() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
Proxy proxy= new Proxy(Type.HTTP, new InetSocketAddress(proxyHost,proxyPort));
requestFactory.setProxy(proxy);
requestFactory.setReadTimeout(readTimeout);
requestFactory.setConnectTimeout(connectTimeout);
return new RestTemplate(requestFactory);
}


}


And I want the service to be scheduled at a fixed interval
The Service Class with a method annotated with @Scheduled is given below



@Service
public class targusTractoscalingScheduler {

private static final Logger logger = LogManager.getLogger(targusTractoscalingScheduler.class);

@Autowired
targusController targusController;

@Autowired RestTemplate restTemplate;

private boolean firstTime = true;

@Value("aaaaaaaaaaaaaaaa")
private String apiKey;

@Value("xxxxxxxxxxxxxxxxxxxxxxx")
private String applicationKey;

@Value("${ddUrl}")
private String ddUrl;

@Value("/filter/instance")
private String ddInstanceApiPath;

@Value("/stop/job/{Tractoscalinggroup}")
private String ddStopJobPath;

/**
* Scheduler method that will run at every predefined interval.
*/

@Scheduled(initialDelayString = "5000", fixedRateString = "10000")
public void targusAsgAndCmdbASgCompare() {
List<targusData> targusDatas = targusController.gettargusData();
if (CollectionUtils.isEmpty(targusDatas)) {
logger.debug("Empty list obtained from targus, so simply exiting from method");
return;
}
processtargusData(targusDatas);
firstTime = false;
}


But the service isnt triggering,the springboot documenattion also gives similar implementation.










share|improve this question




















  • 1




    You'll see log only if targusDatas is empty, so instead of waiting log there, put look just after method def with info level and see if job is running!
    – Yogen Rai
    Nov 20 at 0:29
















0














I am trying to schedule a service from spring-boot at a fixed rate with an initial delay,

After deploying, I was expecting that the read method should be executed after 5 secs and every 10 seconds, but nothing is displayed in the console.
Here is my main application class



@SpringBootApplication
@EnableScheduling
public class ArgusAPIApplication {

@Value("${proxy.host}")
private String proxyHost;
@Value(("${proxy.port}"))
private int proxyPort;
@Value(("${readTimeout}"))
private int readTimeout;
@Value(("${connectTimeout}"))
private int connectTimeout;


public static void main(String args) {
SpringApplication.run(ArgusAPIApplication.class, args);
}

@Bean
public RestTemplate restTemplate() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
Proxy proxy= new Proxy(Type.HTTP, new InetSocketAddress(proxyHost,proxyPort));
requestFactory.setProxy(proxy);
requestFactory.setReadTimeout(readTimeout);
requestFactory.setConnectTimeout(connectTimeout);
return new RestTemplate(requestFactory);
}


}


And I want the service to be scheduled at a fixed interval
The Service Class with a method annotated with @Scheduled is given below



@Service
public class targusTractoscalingScheduler {

private static final Logger logger = LogManager.getLogger(targusTractoscalingScheduler.class);

@Autowired
targusController targusController;

@Autowired RestTemplate restTemplate;

private boolean firstTime = true;

@Value("aaaaaaaaaaaaaaaa")
private String apiKey;

@Value("xxxxxxxxxxxxxxxxxxxxxxx")
private String applicationKey;

@Value("${ddUrl}")
private String ddUrl;

@Value("/filter/instance")
private String ddInstanceApiPath;

@Value("/stop/job/{Tractoscalinggroup}")
private String ddStopJobPath;

/**
* Scheduler method that will run at every predefined interval.
*/

@Scheduled(initialDelayString = "5000", fixedRateString = "10000")
public void targusAsgAndCmdbASgCompare() {
List<targusData> targusDatas = targusController.gettargusData();
if (CollectionUtils.isEmpty(targusDatas)) {
logger.debug("Empty list obtained from targus, so simply exiting from method");
return;
}
processtargusData(targusDatas);
firstTime = false;
}


But the service isnt triggering,the springboot documenattion also gives similar implementation.










share|improve this question




















  • 1




    You'll see log only if targusDatas is empty, so instead of waiting log there, put look just after method def with info level and see if job is running!
    – Yogen Rai
    Nov 20 at 0:29














0












0








0







I am trying to schedule a service from spring-boot at a fixed rate with an initial delay,

After deploying, I was expecting that the read method should be executed after 5 secs and every 10 seconds, but nothing is displayed in the console.
Here is my main application class



@SpringBootApplication
@EnableScheduling
public class ArgusAPIApplication {

@Value("${proxy.host}")
private String proxyHost;
@Value(("${proxy.port}"))
private int proxyPort;
@Value(("${readTimeout}"))
private int readTimeout;
@Value(("${connectTimeout}"))
private int connectTimeout;


public static void main(String args) {
SpringApplication.run(ArgusAPIApplication.class, args);
}

@Bean
public RestTemplate restTemplate() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
Proxy proxy= new Proxy(Type.HTTP, new InetSocketAddress(proxyHost,proxyPort));
requestFactory.setProxy(proxy);
requestFactory.setReadTimeout(readTimeout);
requestFactory.setConnectTimeout(connectTimeout);
return new RestTemplate(requestFactory);
}


}


And I want the service to be scheduled at a fixed interval
The Service Class with a method annotated with @Scheduled is given below



@Service
public class targusTractoscalingScheduler {

private static final Logger logger = LogManager.getLogger(targusTractoscalingScheduler.class);

@Autowired
targusController targusController;

@Autowired RestTemplate restTemplate;

private boolean firstTime = true;

@Value("aaaaaaaaaaaaaaaa")
private String apiKey;

@Value("xxxxxxxxxxxxxxxxxxxxxxx")
private String applicationKey;

@Value("${ddUrl}")
private String ddUrl;

@Value("/filter/instance")
private String ddInstanceApiPath;

@Value("/stop/job/{Tractoscalinggroup}")
private String ddStopJobPath;

/**
* Scheduler method that will run at every predefined interval.
*/

@Scheduled(initialDelayString = "5000", fixedRateString = "10000")
public void targusAsgAndCmdbASgCompare() {
List<targusData> targusDatas = targusController.gettargusData();
if (CollectionUtils.isEmpty(targusDatas)) {
logger.debug("Empty list obtained from targus, so simply exiting from method");
return;
}
processtargusData(targusDatas);
firstTime = false;
}


But the service isnt triggering,the springboot documenattion also gives similar implementation.










share|improve this question















I am trying to schedule a service from spring-boot at a fixed rate with an initial delay,

After deploying, I was expecting that the read method should be executed after 5 secs and every 10 seconds, but nothing is displayed in the console.
Here is my main application class



@SpringBootApplication
@EnableScheduling
public class ArgusAPIApplication {

@Value("${proxy.host}")
private String proxyHost;
@Value(("${proxy.port}"))
private int proxyPort;
@Value(("${readTimeout}"))
private int readTimeout;
@Value(("${connectTimeout}"))
private int connectTimeout;


public static void main(String args) {
SpringApplication.run(ArgusAPIApplication.class, args);
}

@Bean
public RestTemplate restTemplate() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
Proxy proxy= new Proxy(Type.HTTP, new InetSocketAddress(proxyHost,proxyPort));
requestFactory.setProxy(proxy);
requestFactory.setReadTimeout(readTimeout);
requestFactory.setConnectTimeout(connectTimeout);
return new RestTemplate(requestFactory);
}


}


And I want the service to be scheduled at a fixed interval
The Service Class with a method annotated with @Scheduled is given below



@Service
public class targusTractoscalingScheduler {

private static final Logger logger = LogManager.getLogger(targusTractoscalingScheduler.class);

@Autowired
targusController targusController;

@Autowired RestTemplate restTemplate;

private boolean firstTime = true;

@Value("aaaaaaaaaaaaaaaa")
private String apiKey;

@Value("xxxxxxxxxxxxxxxxxxxxxxx")
private String applicationKey;

@Value("${ddUrl}")
private String ddUrl;

@Value("/filter/instance")
private String ddInstanceApiPath;

@Value("/stop/job/{Tractoscalinggroup}")
private String ddStopJobPath;

/**
* Scheduler method that will run at every predefined interval.
*/

@Scheduled(initialDelayString = "5000", fixedRateString = "10000")
public void targusAsgAndCmdbASgCompare() {
List<targusData> targusDatas = targusController.gettargusData();
if (CollectionUtils.isEmpty(targusDatas)) {
logger.debug("Empty list obtained from targus, so simply exiting from method");
return;
}
processtargusData(targusDatas);
firstTime = false;
}


But the service isnt triggering,the springboot documenattion also gives similar implementation.







java spring spring-boot






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 0:18

























asked Nov 20 at 0:12









Siraj Syed

41210




41210








  • 1




    You'll see log only if targusDatas is empty, so instead of waiting log there, put look just after method def with info level and see if job is running!
    – Yogen Rai
    Nov 20 at 0:29














  • 1




    You'll see log only if targusDatas is empty, so instead of waiting log there, put look just after method def with info level and see if job is running!
    – Yogen Rai
    Nov 20 at 0:29








1




1




You'll see log only if targusDatas is empty, so instead of waiting log there, put look just after method def with info level and see if job is running!
– Yogen Rai
Nov 20 at 0:29




You'll see log only if targusDatas is empty, so instead of waiting log there, put look just after method def with info level and see if job is running!
– Yogen Rai
Nov 20 at 0:29












1 Answer
1






active

oldest

votes


















1














Here is an example :



@EnableScheduling
@SpringBootApplication
public class MyExampleCronApplication {

public static void main(String args) {
SpringApplication.run(MyExampleCronApplication.class, args);
}

@Scheduled(initialDelay=5000,fixedRate=10000)
public void test() {
System.out.println(Date.from(Instant.now()).getSeconds());
}
}


The output :



enter image description here



NB: i separate the code by putting the scheduled methode in a service and it work find.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384434%2fschedule-doesnt-trigger-the-service-at-a-fixed-time%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Here is an example :



    @EnableScheduling
    @SpringBootApplication
    public class MyExampleCronApplication {

    public static void main(String args) {
    SpringApplication.run(MyExampleCronApplication.class, args);
    }

    @Scheduled(initialDelay=5000,fixedRate=10000)
    public void test() {
    System.out.println(Date.from(Instant.now()).getSeconds());
    }
    }


    The output :



    enter image description here



    NB: i separate the code by putting the scheduled methode in a service and it work find.






    share|improve this answer




























      1














      Here is an example :



      @EnableScheduling
      @SpringBootApplication
      public class MyExampleCronApplication {

      public static void main(String args) {
      SpringApplication.run(MyExampleCronApplication.class, args);
      }

      @Scheduled(initialDelay=5000,fixedRate=10000)
      public void test() {
      System.out.println(Date.from(Instant.now()).getSeconds());
      }
      }


      The output :



      enter image description here



      NB: i separate the code by putting the scheduled methode in a service and it work find.






      share|improve this answer


























        1












        1








        1






        Here is an example :



        @EnableScheduling
        @SpringBootApplication
        public class MyExampleCronApplication {

        public static void main(String args) {
        SpringApplication.run(MyExampleCronApplication.class, args);
        }

        @Scheduled(initialDelay=5000,fixedRate=10000)
        public void test() {
        System.out.println(Date.from(Instant.now()).getSeconds());
        }
        }


        The output :



        enter image description here



        NB: i separate the code by putting the scheduled methode in a service and it work find.






        share|improve this answer














        Here is an example :



        @EnableScheduling
        @SpringBootApplication
        public class MyExampleCronApplication {

        public static void main(String args) {
        SpringApplication.run(MyExampleCronApplication.class, args);
        }

        @Scheduled(initialDelay=5000,fixedRate=10000)
        public void test() {
        System.out.println(Date.from(Instant.now()).getSeconds());
        }
        }


        The output :



        enter image description here



        NB: i separate the code by putting the scheduled methode in a service and it work find.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 20 at 1:16

























        answered Nov 20 at 0:45









        TinyOS

        7711828




        7711828






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384434%2fschedule-doesnt-trigger-the-service-at-a-fixed-time%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            Origin of the phrase “under your belt”?