Task Executor get execute before object initiliazation

Hi,

I am using Task Executor to run some activities in background.But i some scenario object used in TaskExecutor are not fully initialized or the values which is set in object are not loaded to when we get these values. Can we delay the task executor to only run when objects are initilazed or any other way to fix this.


 @Qualifier(value = "applicationTaskExecutor")
    @Autowired
    private TaskExecutor taskExecutor;

taskExecutor.execute(() -> {
                            // code to be executed in a new thread
                            try{
                                apiService.apiAudit(submissionData.toString());
                            }catch (Exception e){
                                log.info("Exception e"+e);
                                e.printStackTrace();
                            }
                        });

Hello!

TaskExecutor is used only for execution task and does not provide “delay” feature. For delayed tasks you can take a look at:

  • Quartz :: Jmix Documentation - Quartz add-on
  • org.springframework.scheduling.TaskScheduler - but it seems cannot be configured to execute only ones.

Could you clarify what does your task do? Does it load data from DB?

Task are used to call apis or perform database activity. which is now working but there seem to be concern task-executor is not getting executed sometimes, but the business login written in that execute some line of code and get drop after that. If we check in logs same task-5 logs are getting printed properly as per code but after sometime the same thread task-5 is performing other activity and previous logs get untrace.
Any solution to synchronise the task executor. Multiple task-executor are created in project will it be possible to synchronise.