Serverresponse Way
@Configuration Public classrouterfunctionconfiguration {@Bean//@Autowired PublicRouterfunction<serverresponse>Personfindall (userrepository userrepository) {returnRouterfunctions.route (Requestpredicates.get ("/person/find/all"), Request-{Collection<User> users =Userrepository.findall (); Flux<User> Userflux =flux.fromiterable (users); returnServerresponse.ok (). Body (Userflux,user.class); }); }}
Test
@Test
public void Threadtestorderby () throws Interruptedexception {
Final Long id=141284830240768l;
int threadcount=100000;
Final Countdownlatch begin = new Countdownlatch (1);
Final Countdownlatch end = new Countdownlatch (threadcount);
Final int[] result={0,0};
Final Object lock = new Object ();
Executorservice executorservice = executors.newfixedthreadpool (100);
Long Time1=system.currenttimemillis ();
for (int i = 0; i < ThreadCount; i++) {
Thread thread = new Thread (new Runnable () {
@Override
public void Run () {
try {
Begin.await ();
HTTPPARAMSVO HTTPPARAMSVO = new Httpparamsvo (new Httpsecretvo (Appkey,appsecret), params);
String ResultS = httpclientsecretsendutil.get (URL, HTTPPARAMSVO);
Synchronized (lock) {
result[0]++;
}
} catch (Exception ex) {
Synchronized (lock) {
result[1]++;
}
Ex.printstacktrace ();
}finally{
End.countdown ();
}
}
});
Executorservice.submit (thread);
}
System.out.println (threadcount+ "Start of Thread");
Begin.countdown ();
End.await ();
Long Time2=system.currenttimemillis ();
System.out.println ("Time-consuming:" + (time2-time1)/1000+ "seconds");
System.out.println (threadcount+ "End of Thread Update");
SYSTEM.OUT.PRINTLN ("Success" +result[0]+ ", Failure" +result[1]);
}
Take
servlet mode
@GetMapping ("/person/find/all") @ResponseBody public collection<user> FindAll () { returnthis. Userrepository.findall (); }
Test Ibid.
Results
Summarize 100W threads in a case
Spring 5 provides a webflux that is 17 seconds slower than the servlet model
Spring5 Webflux Test