package net.educoder.ecsonar.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;

import java.util.concurrent.*;

@Configuration
public class ThreadPoolConfig {

    @Bean("sonarScannerPool")
    @Primary
    public ExecutorService sonarScannerPool() {
        ThreadFactory sonarScannerPool = new CustomizableThreadFactory("sonarScanner-pool-");
        return new ThreadPoolExecutor(10, 10, 0,
                TimeUnit.SECONDS, new ArrayBlockingQueue<>(10000), sonarScannerPool,
                new ThreadPoolExecutor.AbortPolicy());
    }


    @Bean("sonarQueryResultPool")
    public ExecutorService queryResultPool() {
        ThreadFactory sonarQueryResultPool = new CustomizableThreadFactory("sonarQueryResult-pool-");
        return new ThreadPoolExecutor(5, 5, 0,
                TimeUnit.SECONDS, new ArrayBlockingQueue<>(10000),
                sonarQueryResultPool,
                new ThreadPoolExecutor.AbortPolicy());
    }

}
