Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange behavior with taskScheduler pool

Tags:

java

spring

I have two spring boot app (1.4.3.RELEASE) which are on the same server. The app A is a monolithic app which contains a part of code used to process alerts and the app B is a new dedicated app which only process alerts. The goal here is to break the monolotic app in small apps. For now, the two codes run together because I have old systems which always call the app A.

The two app have a taskScheduler configured based on a ThreadPoolTaskScheduler.

@Configuration
public class TaskSchedulerConfig {

    @Bean
    public TaskScheduler taskScheduler() {
        ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
        threadPoolTaskScheduler.setWaitForTasksToCompleteOnShutdown(true);
        threadPoolTaskScheduler.setPoolSize(100);

        return threadPoolTaskScheduler;
    }
}

Yesterday, I have experienced a strange behavior :

  1. An alert has been detected and sent to the new app B -> OK
  2. The app B received the alert and start to process it based on the taskScheduler -> OK
  3. The first step has been processed by the app B -> OK
  4. The second step has been processed by the app A -> NOK, strange behavior
  5. The third step has been processed by the app B as expected -> OK

How can this be possible? For me, each taskScheduler is attached to the app which created it. Where am I wrong?

UPDATE

I have a real box which emit alerts. Those alerts must be processed by a new application. But I have also old box which have not migrate to the new system. So I have the processing code in two different projects.

I have a new box with the new code which have created an alert on the new system. This alert generate a state machine which is processed in async with a task scheduler. After alert creation, the new app starts to process the state machine and at the middle of the processing the old application wake up and process a step of the alert. After that, the new application wake up again and normally close the alert.

The problem is : why the old application wake up to process an alert? Is there a known issue with a threadPoolTaskScheduler?

like image 781
Franck Anso Avatar asked Apr 21 '17 14:04

Franck Anso


People also ask

What is ThreadPoolTaskScheduler?

ThreadPoolTaskScheduler ThreadPoolTaskScheduler is well suited for internal thread management, as it delegates tasks to the ScheduledExecutorService and implements the TaskExecutor interface – so that single instance of it is able to handle asynchronous potential executions as well as the @Scheduled annotation.

What is pool size in Task Scheduler?

The default scheduler pool size in spring-boot is only one. In org. springframework. scheduling.

What is ScheduledTaskRegistrar?

public class ScheduledTaskRegistrar extends Object implements ScheduledTaskHolder, InitializingBean, DisposableBean. Helper bean for registering tasks with a TaskScheduler , typically using cron expressions.


Video Answer


1 Answers

There is no way that two different applications have this behavior since they are running in isolated processes. Threads (of the same process) run in a shared memory space, while processes run in separate memory spaces, so there is no 'bridge' between them.

If they share the same database, they might be listening to the same events, but only if you have that logic implemented by you.

If I had to guess, given that both are webapps I'd say that there might be some HTTP call somewhere in the code, still aiming to an old endpoint, or some other trigger (crons?) inside the server that is kickstarting the old app.

like image 165
Tomas Fornara Avatar answered Oct 25 '22 23:10

Tomas Fornara