普通JDK自带的线程池时无法实现线程池的自动切换,基于监控与上下文自动切换的需求,封住了一套taxi开头的线程池,接入方式很简单,它的使用方式与Jdk的使用基本方式一致,只需在对应的类前加一个Taxi,现将对应方式列举如下: 1)Executors<-------->TaxiExecutors Example: private final ExecutorService producerPool = TaxiExecutors.newCachedThreadPool(new ThreadFactoryBuilder("Scheduled-EncourageOrderPushProducer-scheduler"));
2)ScheduledThreadPoolExecutor<-------->WrapTaxiScheduledThreadPoolExecutor Example: private WrapTaxiScheduledThreadPoolExecutor executor = new WrapTaxiScheduledThreadPoolExecutor(2, new ThreadFactoryBuilder("TimerMonitorImpl-executor"));
3)ThreadPoolExecutor<-------->TaxiThreadPoolExecutor Example:private final ExecutorService dataFlushExecutor = new TaxiThreadPoolExecutor(100, 200, 60L,TimeUnit.SECONDS, new LinkedBlockingDeque(5000000), new ThreadFactoryBuilder( "DataFlush-executor"));
4)Callable<-------->TaxiCallableWrapper Example:public Future submit(Callable task) { return schedule(new TaxiCallableWrapper(task), 0, TimeUnit.NANOSECONDS); }
5)Runnable<-------->TaxiRunnableWrapper Example:public void execute(Runnable command) { schedule(new TaxiRunnableWrapper(command), 0, TimeUnit.NANOSECONDS); }
应用依赖的Log4j中做如下配置