Skip to content

Commit

Permalink
v3.6.0 ThreadPoolTaskExcutor 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
jongwuner committed Apr 29, 2020
1 parent 448661b commit 5b0b3a1
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public HttpMessageConverter<String> responseBodyConverter() {
return new StringHttpMessageConverter(Charset.forName("UTF-8"));
}

@Bean
FilterRegistrationBean shallowEtagBean () {
FilterRegistrationBean frb = new FilterRegistrationBean();
frb.setFilter(new ShallowEtagHeaderFilter());
frb.addUrlPatterns("/mobile/*");
frb.setOrder(2);
return frb;
}
//@Bean
//FilterRegistrationBean shallowEtagBean () {
// FilterRegistrationBean frb = new FilterRegistrationBean();
// frb.setFilter(new ShallowEtagHeaderFilter());
// frb.addUrlPatterns("/mobile/*");
// frb.setOrder(2);
// return frb;
//}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.hours22.system_monitor_ver11.async;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

Expand All @@ -11,8 +10,6 @@
@Configuration
@EnableAsync
public class SpringAsyncConfig {


//Common
@Bean(name = "threadPoolHome")
public Executor threadPoolHomeExecutor() {
Expand Down Expand Up @@ -75,8 +72,8 @@ public Executor threadPoolPcMsgReturnExecutor() {
public Executor threadPoolMobileGetPcsExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
taskExecutor.setMaxPoolSize(100);
taskExecutor.setQueueCapacity(30);
taskExecutor.setMaxPoolSize(20);
taskExecutor.setQueueCapacity(10);
taskExecutor.setThreadNamePrefix("MobilePcs-");
taskExecutor.initialize();
return taskExecutor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;

import javax.servlet.AsyncContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.HttpRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Controller;
Expand All @@ -23,7 +27,7 @@
import com.hours22.system_monitor_ver11.client.ServerTimer;

@Controller
@RequestMapping(value = "/async/callable", method = RequestMethod.GET)
//@RequestMapping(value = "/async/callable", method = RequestMethod.GET)
public class AsyncTestController {

String InterruptKey = null;
Expand Down Expand Up @@ -95,28 +99,18 @@ public void GetThreadIdTest(@PathVariable String thName) {
}
}

@Async("threadPoolHome")
@RequestMapping(value = "/test2", method = RequestMethod.GET)
public Future<String> GetThreadIdTest2() {
Set<Thread> setOfThread = Thread.getAllStackTraces().keySet();
@Async("threadPoolHome")
@RequestMapping(value = "/test22", method = RequestMethod.GET)
public CompletableFuture<ResponseEntity<Map<String, String>>> GetThreadIdTest22() {
Map<String, String> map = new HashMap<String, String>();
map.put("key", "1");
map.put("keys", "2");

System.out.println("----------------------------------------------------------------------------------------------------");
System.out.println("Input : /async/callable/threads/");
System.out.println("GetThreadIdTesting.....");
System.out.println("현재 Thread ID : " + Thread.currentThread().getId());
System.out.println("현재 Thread Name : " + Thread.currentThread().getName());
//Iterate over set to find yours
/*
for(Thread thread : setOfThread){
System.out.println("Active Thread's [ Number : " +thread.getId()+" / Name : "+thread.getName()+" ] ");
String res = thread.getName();
if(res.equals(thName)) {
thread.interrupt();
System.out.println("******"+res+" 스레드를 종료시킵니다.******");
}
}
*/
return new AsyncResult<>("hahaha");

String info = "123123123";
System.out.println("ID : "+Thread.currentThread().getId());
System.out.println("NAME : "+Thread.currentThread().getName());
System.out.println(info);
return CompletableFuture.completedFuture(ResponseEntity.accepted().body(map));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -66,7 +67,7 @@ public CompletableFuture<ResponseEntity<String>> GetIndex(WebRequest req, HttpSe
System.out.println("--------------------------------------------------------------------------------------------");
System.out.println("Input : / <- GET method [Client Ip : "+ cic.getClientIp(request) +" ] at " + transFormat.format(new Date()));
cache.SetCache(req.getHeader("If-None-Match"));
return CompletableFuture.completedFuture(new ResponseEntity<String>(msg, HttpStatus.OK));
return CompletableFuture.completedFuture(ResponseEntity.ok().body(msg));
}

@RequestMapping(value = "/testpage", method = RequestMethod.GET)
Expand All @@ -79,15 +80,15 @@ public CompletableFuture<ResponseEntity<String>> GetIndex(WebRequest req, HttpSe


@RequestMapping(value = "/pc/{id}", method = RequestMethod.GET)
public @ResponseBody String GetPcInstanceData(HttpServletRequest req, HttpServletResponse response, @PathVariable String id) throws IOException {
public CompletableFuture<ResponseEntity<String>> GetPcInstanceData(HttpServletRequest req, HttpServletResponse response, @PathVariable String id) throws IOException {
System.out.println("--------------------------------------------------------------------------------------------");
System.out.println("Input : /pc/"+ id +" <- GET method [Client Ip : "+ cic.getClientIp(req) + " ] at " + transFormat.format(new Date()));

//lc.getConnection();
String res = lc.getConnectionHgetall(id);
//lc.getConnectionExit();

return res;
return CompletableFuture.completedFuture(ResponseEntity.ok().body(res));
}

@RequestMapping(value = "/pc/{id}", method = RequestMethod.POST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import com.hours22.system_monitor_ver11.vo.PcData;

@Controller
@WebServlet(asyncSupported = true)
public class MobileController{
@Autowired
ObjectMapper ojm;
Expand All @@ -73,32 +72,33 @@ public class MobileController{
@CrossOrigin("*")
@Async(value = "threadPoolMobileGetPcs")
@RequestMapping(value = "/mobile/pc", method = RequestMethod.GET)
public Future<ResponseEntity<String>> GetPcData(WebRequest req, HttpServletRequest request, HttpServletResponse response) throws IOException {
public CompletableFuture<ResponseEntity<String>> GetPcData(WebRequest req, HttpServletRequest request, HttpServletResponse response) throws IOException {


if (req.checkNotModified(cache.GetCache())) {
return null;
}
//if (req.checkNotModified(cache.GetCache())) {
// return null;
//}

System.out.println("--------------------------------------------------------------------------------------------");
System.out.println("Input : /mobile/pc <- GET method [Client Ip : "+ cic.getClientIp(request)+"] at "+transFormat.format(new Date()) );

//lc.getConnection();

String json = ojm.writeValueAsString(dss.GetAllTypeDataRedis("PC", "pcs"));

json = dss.PrettyPrinter(json);
System.out.println(json);
//lc.getConnectionExit();
cache.SetCache(req.getHeader("If-None-Match"));
System.out.println(req.getHeader("If-None-Match"));
return new AsyncResult<>(new ResponseEntity<String>(json, HttpStatus.OK));
//cache.SetCache(req.getHeader("If-None-Match"));
//System.out.println(req.getHeader("If-None-Match"));
return CompletableFuture.completedFuture(ResponseEntity.ok().body(json));
}


@CrossOrigin("*")
@Async(value = "threadPoolMobileGetPcData")
@RequestMapping(value = "/mobile/pc/{id}/data", method = RequestMethod.GET)
public Future<ResponseEntity<String>> GetPcRamCpuData(WebRequest req, HttpServletRequest request, HttpServletResponse response, @PathVariable String id) throws IOException {
public CompletableFuture<ResponseEntity<String>> GetPcRamCpuData(WebRequest req, HttpServletRequest request, HttpServletResponse response, @PathVariable String id) throws IOException {
response.setContentType("application/json;charset=UTF-8");
if (req.checkNotModified(cache.GetCache())) {
return null;
Expand All @@ -115,7 +115,7 @@ public Future<ResponseEntity<String>> GetPcRamCpuData(WebRequest req, HttpServle
//response.getWriter().print(json);
//lc.getConnectionExit();
cache.SetCache(req.getHeader("If-None-Match"));
return new AsyncResult<>(new ResponseEntity(json, HttpStatus.OK));
return CompletableFuture.completedFuture(ResponseEntity.ok().body(json));
}

@CrossOrigin("*")
Expand Down Expand Up @@ -147,7 +147,7 @@ public CompletableFuture<ResponseEntity<Map<String, String>>> PostPcPower(WebReq
Map<String, String> jsonObject = new HashMap<String, String>();
jsonObject.put("id", id);
jsonObject.put("msg", "false");
return CompletableFuture.completedFuture(new ResponseEntity<Map<String, String>>(jsonObject, HttpStatus.OK));
return CompletableFuture.completedFuture(ResponseEntity.badRequest().body(jsonObject));
}
lc.getConnectionHset(id, map);
//lc.getConnectionExit();
Expand All @@ -159,7 +159,7 @@ public CompletableFuture<ResponseEntity<Map<String, String>>> PostPcPower(WebReq
jsonObject.put("endTime", endTime);
jsonObject.put("msg", "true");
cache.SetCache(req.getHeader("If-None-Match"));
return CompletableFuture.completedFuture(new ResponseEntity<Map<String, String>>(jsonObject, HttpStatus.OK));
return CompletableFuture.completedFuture(ResponseEntity.ok().body(jsonObject));
}

@CrossOrigin("*")
Expand All @@ -175,17 +175,17 @@ public CompletableFuture<ResponseEntity<Map<String, String>>> GetAdminLogin(WebR
if(type.equals("admin") && ret.equals("false")) {
//lc.getConnectionExit();
jsonObject.put("msg", "false");
return CompletableFuture.completedFuture(new ResponseEntity<Map<String, String>>(jsonObject, HttpStatus.NON_AUTHORITATIVE_INFORMATION));
return CompletableFuture.completedFuture(ResponseEntity.badRequest().body(jsonObject));
}
//lc.getConnectionExit();
auth.put("msg", "true");
return CompletableFuture.completedFuture(new ResponseEntity<Map<String, String>>(auth, HttpStatus.OK));
return CompletableFuture.completedFuture(ResponseEntity.ok().body(auth));
}

@CrossOrigin("*")
@Async(value = "threadPoolMobileClass")
@RequestMapping(value = "/mobile/class", method = RequestMethod.GET)
public CompletableFuture<ResponseEntity<Map<String, String>>> GetAllClassData(WebRequest req, HttpServletRequest request, HttpServletResponse response) throws IOException {
public CompletableFuture<ResponseEntity<String>> GetAllClassData(WebRequest req, HttpServletRequest request, HttpServletResponse response) throws IOException {

if (req.checkNotModified(cache.GetCache())) {
return null;
Expand All @@ -197,14 +197,13 @@ public CompletableFuture<ResponseEntity<Map<String, String>>> GetAllClassData(We

//lc.getConnection();

Map<String, String> map = dss.GetAllTypeDataRedis("CLASS", "classes");
//String json = ojm.writeValueAsString(dss.GetAllTypeDataRedis("CLASS", "classes"));
//json = dss.PrettyPrinter(json);
System.out.println(map);
String json = ojm.writeValueAsString(dss.GetAllTypeDataRedis("CLASS", "classes"));
json = dss.PrettyPrinter(json);
System.out.println(json);

//lc.getConnectionExit();
cache.SetCache(req.getHeader("If-None-Match"));
return CompletableFuture.completedFuture(new ResponseEntity<Map<String, String>>(map, HttpStatus.OK));
return CompletableFuture.completedFuture(ResponseEntity.ok().body(json));
}

@CrossOrigin("*")
Expand All @@ -228,7 +227,7 @@ public CompletableFuture<ResponseEntity<String>> GetAllClassPcData(WebRequest re

//lc.getConnectionExit();
cache.SetCache(req.getHeader("If-None-Match"));
return CompletableFuture.completedFuture(new ResponseEntity<String>(json, HttpStatus.OK));
return CompletableFuture.completedFuture(ResponseEntity.ok().body(json));
}

@CrossOrigin("*")
Expand All @@ -250,6 +249,7 @@ public CompletableFuture<ResponseEntity<Map<String, String>>> PostAllClassPcPowe
//lc.getConnectionExit();
cache.SetCache(req.getHeader("If-None-Match"));
map.put("message", "success update!");
return CompletableFuture.completedFuture(new ResponseEntity<Map<String, String>>(map, HttpStatus.OK));
return CompletableFuture.completedFuture(ResponseEntity.ok().body(map));
}

}
Loading

0 comments on commit 5b0b3a1

Please sign in to comment.