1

My application has a cron job that executes every 60 seconds. The application is configured to scale when required onto multiple instances. I only want to execute the task on 1 instance every 60 seconds (On any node).

I did the following changes as per spring profiling.

Changed the bean definition from:

<beans>
<bean id="someBean" .../>
<task:scheduled-tasks>
<task:scheduled ref="someBean" method="execute" cron="0/60 * * * * *"/>
</task:scheduled-tasks>
</beans>

To:

<beans>
  <beans profile="scheduled">
    <bean id="someBean" .../>

    <task:scheduled-tasks>
      <task:scheduled ref="someBean" method="execute" cron="0/60 * * * * *"/>
    </task:scheduled-tasks>
  </beans>
</beans>

Then I set the JVM property to include the below: -Dspring.profiles.active=scheduled

the above property is set on 1 of the four tomcat instances.

My job still does not run. Am i missing out on any configuration? Any guidance would be greatly appreciated. Thanks

  • Can you verify the property correctly set? ..since from spring side everything seems correct/comprehensibly.. – xerx593 Jun 22 '17 at 11:51
  • may i know which property are you referring to. the property set is as below: export JAVA_OPTS="$JAVA_OPTS -DdeploymentMode=demo -Dspring.profiles.active=scheduled" – natasha parab Jun 22 '17 at 12:15
  • ..yes, the "spring.profiles.active", I assume, that it is not correctly set. Spring-logging >= DEBUG can clarify.. – xerx593 Jun 22 '17 at 12:39
  • Hi,i debugged to check the current active profiles and realised that when my server is starting up , it is not picking up 'scheduled' as my active profile although it is set as a jvm property. how can i identify why the profile is not being picked up on start up – natasha parab Jun 27 '17 at 13:19
  • ..from the known facts, it seems, that your `${JAVA_OPTS}` are not picked up on container start. You should investigate the "start script"/the way how you start your "tommy". An alternative location(to set the property) would be `conf/catalina.properties`. – xerx593 Jun 27 '17 at 13:32
  • @xerx593 thanks for your guidance, but i do see the -Dspring.profiles.active=scheduled when i grep for my tomcat process. does that mean that my tomcat is picking up the profile? if yes, it still does not run my jobs. do i need to mention anything in my apllication context? – natasha parab Jun 29 '17 at 10:03
  • @xerx593 i tried setting spring.profiles.active=scheduled in conf/catalina.properties .still does not work. – natasha parab Jul 05 '17 at 08:52
  • @Developer_Mario i believe you faced the same issue as per your post https://stackoverflow.com/questions/40723818/profile-not-getting-picked-from-environment-variable-set-in-tomcat-but-is-pickin/44820277#44820277 – natasha parab Jul 05 '17 at 08:52

0 Answers0