Im uses the same approach as in other threads - checking that a particular host is the right one to run the job. But..
I don't really need tools, but in spring you can use profiles for this. You can probably find a similar solution for your needs. Take a look at http://spring.io/blog/2011/06/21/spring-3-1-m2-testing-with-configuration-classes-and-profiles
You can define two separate beans:
@Configuration @Profile("dev") public class StandaloneDataConfig { @Bean public DataSource dataSource() { return new EmbeddedDatabaseBuilder() .setType(EmbeddedDatabaseType.HSQL) .addScript("classpath:com/bank/config/sql/schema.sql") .addScript("classpath:com/bank/config/sql/test-data.sql") .build(); } } @Configuration @Profile("production") public class JndiDataConfig { @Bean public DataSource dataSource() throws Exception { Context ctx = new InitialContext(); return (DataSource) ctx.lookup("java:comp/env/jdbc/datasource"); } }
and decide which one to enable by switching the profile. This way, your class with the annotated @Scheduled method will only be loaded for a specific profile. Of course, you need to configure the application to include a profile from nodes only. In a spring application, it will be as simple as passing -Dspring.profiles.active = profile to one of them.
source share