asynchronous - Calling @Async method from method which is @Schedule -
i have scheduler listens queue (priorityqueue not mq/jms) @ every 1 second, once got message interested in want perform logic.
so have scheduler runs every second, calling method annotated @async, assuming once call method scheduler running interval.
below sample code, not sure using right pattern or advise. idea once have message should not wait prev processing, , can have multiple threads processing it.
i using spring boot.
@scheduled(fixeddelaystring = "1000", initialdelay = 10000) public void startscheduler() { message msg = queue.peek(); if(msg!=null){ doprocessing(msg); } } @async public void doprocessing(message msg){ // processing // may take 5 seconds. }
Comments
Post a Comment