spring exception thread

 

Spring-Config.xml is configured as follows:

 

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <!--Three, configuration explanation-->

    <!--When a task is to be added to the thread pool through the execute(Runnable) method: -->

    <!--1. If the number of threads in the thread pool is less than corePoolSize at this time, even if the threads in the thread pool are idle, a new thread should be created to process the added task. -->

    <!--2. If the number in the thread pool is equal to corePoolSize at this time, but the buffer queue workQueue is not full, then the task is put into the buffer queue. -->

    <!--3. If the number in the thread pool is greater than corePoolSize at this time, the buffer queue workQueue is full, and the number in the thread pool is less than the maximumPoolSize, create a new thread to process the added task. -->

    <!--4. If the number in the thread pool is greater than corePoolSize at this time, the buffer queue workQueue is full, and the number in the thread pool is equal to the maximumPoolSize, then this task is processed by the strategy specified by the handler. That is: the priority of processing tasks is: core thread corePoolSize, task queue workQueue, maximum thread maximumPoolSize, if all three are full, use handler to process rejected tasks. -->

    <!--5. When the number of threads in the thread pool is greater than corePoolSize, if the idle time of a thread exceeds keepAliveTime, the thread will be terminated. In this way, the thread pool can dynamically adjust the number of threads in the pool. -->

 

       <!--corePoolSize: At least 2 threads in the thread pool are started, and they will not be closed even if they are idle. -->

       <!--maxPoolSize: The maximum number of threads, when corePoolSize is busy, threads will be created, and the total number of threads started cannot be greater than maxPoolSize-->

       <!--queueCapacity: Queue size, when corePoolSize has no idle threads, allow queueCapacity thread tasks to wait, when the queueCapacity queue is full! Only on the basis of corePoolSize, new threads will be created within maxPoolSize!-->

       <!--keepAliveSeconds: In milliseconds, threads larger than corePoolSize will be closed after this time -->

       <!--rejectedExecutionHandler: The specific operation of refusing to execute the task, AbortPolicy indicates that a RejectedExecutionException is thrown. There are several other options. CallerRunsPolicy: The main thread executes the task. After the execution, try to add the next task to the thread pool, which can effectively reduce the speed of adding tasks to the thread pool. -->

       <bean id="taskExecutor"

             class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">

              <property name="corePoolSize" value="30" />

              <property name="maxPoolSize" value="50" />

              <property name="queueCapacity" value="5" />

              <property name="keepAliveSeconds" value="3000" />

              <property name="rejectedExecutionHandler">

                     <bean class="java.util.concurrent.ThreadPoolExecutor$AbortPolicy" />

              </property>

       </bean>

</beans>

The main thread calls as follows

package com.sinitek.sirm.creditrating.threadprocess;

 

import com.sinitek.sirm.creditrating.service.ICalculatorService;

import com.sinitek.sirm.creditrating.service.ScrServiceFactory;

import org.apache.log4j.Logger;

import org.springframework.context.ApplicationContext;

import org.springframework.context.annotation.Scope;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import org.springframework.stereotype.Component;

 

@Component

@Scope("prototype")

// The main thread, used to monitor whether all secondary threads are processed. After processing, export excel. (production version difference)

public class MainThreadProcessCWYC1 implements Runnable {

    private Logger LOGGER = Logger.getLogger(getClass());

    ApplicationContext ctx =

            new ClassPathXmlApplicationContext("Spring-Config.xml");

    ThreadPoolTaskExecutor taskExecutor =

            (ThreadPoolTaskExecutor) ctx.getBean("taskExecutor");

    @Override

    public void run() {

                CalculatorCWYC calculatorCWYC = new CalculatorCWYC();

                taskExecutor.execute(calculatorCWYC);

    }

}

 

The child thread is called as follows:

package com.sinitek.sirm.creditrating.threadprocess;

 

import com.sinitek.sirm.busin.basedata.enumerate.DataSourceType;

import com.sinitek.sirm.busin.basedata.enumerate.PeriodType;

import com.sinitek.sirm.common.setting.utils.SettingUtils;

import com.sinitek.sirm.creditrating.ScrConsts;

import com.sinitek.sirm.creditrating.ScrSettings;

import com.sinitek.sirm.creditrating.calculator.CalcDataQuery;

import com.sinitek.sirm.creditrating.datas.DatasManager;

import com.sinitek.sirm.creditrating.entity.FinanceIndicator;

import com.sinitek.sirm.creditrating.entity.ICalculator;

import com.sinitek.sirm.creditrating.enums.AnnualType;

import com.sinitek.sirm.creditrating.service.ICalculatorService;

import com.sinitek.sirm.creditrating.service.ICapitalTrimService;

import com.sinitek.sirm.creditrating.service.ScrServiceFactory;

import com.sinitek.sirm.creditrating.service.impl.CapitalTrimServiceImpl;

import org.apache.log4j.Logger;

import org.springframework.context.annotation.Scope;

import org.springframework.stereotype.Component;

import org.springframework.util.StopWatch;

 

import java.util.List;

import java.util.Map;

import java.util.concurrent.CountDownLatch;

 

@Component

@Scope("prototype")

public class CalculatorCWYC implements Runnable {

    private Logger LOGGER = Logger.getLogger(getClass());

 

    public CalculatorCWYC() {

 

    }

 

    @Override

    public void run() {

 

    }

 

}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326820682&siteId=291194637