How do I schedule a task to run once?

While the java.util.Timer used to be a good way to schedule future tasks, it is now preferable1 to instead use the classes in the java.util.concurrent package. There is a ScheduledExecutorService that is designed specifically to run a command after a delay (or to execute them periodically, but that’s not relevant to this question). It has … Read more

Difference between * and ? in Spring @Scheduled(cron=”…..”)

The tutorial is outdated. The symbol ? means exactly the same as the symbol *. As of Spring version 3.1.2.RELEASE, the call hierarchy is the following: The constructor CronTrigger(String) calls the constructor CronSequenceGenerator(String) CronSequenceGenerator(String) calls parse(String) parse(String) calls setDays(BitSet bits, String field, int max). Its implementation is clear: private void setDays(BitSet bits, String field, int … Read more

How to schedule a MySQL query?

you have 2 basic options (at least): 1, Take a look at Event Scheduler First create table eg. stock_dumps with fields itemcode, quantity, avgcost, ttlval,dump_date (DATETIME) CREATE EVENT `Dumping_event` ON SCHEDULE EVERY 1 DAY ON COMPLETION NOT PRESERVE ENABLE COMMENT ” DO BEGIN INSERT INTO stock_dumps(itemcode, quantity, avgcost, ttlval,dump_date) SELECT itmcode, quantity, avgcost, (avgcost * … Read more

How to use Timer class to call a method, do something, reset timer, repeat?

If you want to simply use Timer, I would do something like this: public class TestClass { public long myLong = 1234; public static void main(String[] args) { final TestClass test = new TestClass(); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { test.doStuff(); } }, 0, test.myLong); } public void … Read more

How does a Celery worker consuming from multiple queues decide which to consume from first?

From my testing, it processes multiple queues round-robin style. If I use this test code: from celery import task import time @task def my_task(item_id): time.sleep(0.5) print(‘Processing item “%s”…’ % item_id) def add_items_to_queue(queue_name, items_count): for i in xrange(0, items_count): my_task.apply_async((‘%s-%d’ % (queue_name, i),), queue=queue_name) add_items_to_queue(‘queue1’, 10) add_items_to_queue(‘queue2’, 10) add_items_to_queue(‘queue3’, 5) And start the queue with (using … Read more

Spring Boot : Getting @Scheduled cron value from database

you can add a bean to get cron value from database in the SpringBootApplication main class or in any of the configuration class. Example code is below: @Autowired private CronRepository cronRepo; @Bean public int getCronValue() { return cronRepo.findOne(“cron”).getCronValue(); } you should create a table and provide suitable values in the database. After that you can … Read more