package com.crm.manager.configuration;

import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.Semaphore;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created by max on 2020/6/18.
 */
@Component
public class ThreadPoolConfig {


    /**
     * 更新交易账户使用的信号量
     */
    public static final Semaphore LOGIN_VALID_SEMAPHORE = new Semaphore(1);

    @Bean
    public ListeningExecutorService listeningExecutorService() {
        ThreadPoolExecutor threadPoolExecutor =
                new ThreadPoolExecutor(4, 8, 0L, TimeUnit.SECONDS, new LinkedBlockingDeque<>());

        return MoreExecutors.listeningDecorator(threadPoolExecutor);
    }

}
