Spring configuration file Add thread pool configuration
<bean id= "Taskexecutor"
class= "Org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor" >
<!--Core threads--
<property name= "Corepoolsize" value= "3"/>
<!--max Threads--
< Property Name= "Maxpoolsize" value= "ten"/>
<!--queue Maximum length >=mainexecutor.maxsize--
<property Name= "queuecapacity" value= "/>
<!--thread pool to maintain idle time allowed by thread--
<property name=" Keepaliveseconds " Value= the/>
<!--thread Pool handles the policy of rejecting a task (a wireless thread is available) Threadpoolexecutor.callerrunspolicy policy, the caller's thread executes the task, and if the actuator is closed, is discarded. --
<property name= "Rejectedexecutionhandler" >
<bean class= " Java.util.concurrent.threadpoolexecutor$callerrunspolicy "/>
</property>
</bean>
Controller class
Package Com.test.controller;
Import Java.util.HashMap;
Import Java.util.Map;
Import Java.util.UUID;
Import Javax.servlet.http.HttpServletRequest;
Import org.springframework.beans.factory.annotation.Autowired;
Import Org.springframework.core.task.TaskExecutor;
Import Org.springframework.stereotype.Controller;
Import Org.springframework.web.bind.annotation.ModelAttribute;
Import org.springframework.web.bind.annotation.RequestMapping;
Import Org.springframework.web.bind.annotation.ResponseBody;
Import Com.test.entity.Order;
Import Com.test.entity.Test;
Import Com.test.service.TestService; @Controller @RequestMapping ("/test") public class TestController {@Autowired private taskexecutor execut
Or
@Autowired Testservice Testservice;
@ResponseBody @RequestMapping ("/order") public map<string, object> test (HttpServletRequest request) {
Thread pool + sync block Executor.execute (new Runnable () { @Override public void Run () {synchronized (testservice) {tes
Tservice.insert (order);
}
}
});
return null; }
}
Database has a field num value of: 382
HTTP every request, NUM will-1
Simulate concurrent 500 requests
The result is as shown: