๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๋ฐ˜์‘ํ˜•

๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ96

[JAVA] Runnable ๊ณผ Thread์˜ ์ฐจ์ด ์œ„ ์˜ˆ์ œ ์†Œ์Šค์— ์žˆ๋Š” Runnable์ด๋ž€ ๊ฐ„๋‹จํ•˜๊ฒŒ ๋งํ•ด์„œ Thread๋ฅผ ์ธํ„ฐํŽ˜์ด์Šคํ™”ํ•œ ๊ฒƒ์ธ๋ฐ, Java์—์„œ๋Š” ๋‹ค์ค‘ ์ƒ์†์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๋ฏ€๋กœ Thread๋ฅผ ์ƒ์† ๋ฐ›์ง€ ๋ชปํ•˜๋Š” ๊ฒฝ์šฐ extends Thread๊ฐ€ ์•„๋‹Œ implements๋กœ Runnable๋กœ ์ฒ˜๋ฆฌ ํ•  ์ˆ˜ ์žˆ๋‹ค. extends Thread public class ThreadTest extends Thread { public void run() { System.out.println("thread"); } } ThreadTest threadTest = new ThreadTest(); threadTest.start(); implements Runnable public class ThreadTest implements Runnable { public void .. 2022. 5. 16.
[Web] ๋™๊ธฐ ๋ฐฉ์‹๊ณผ ๋น„๋™๊ธฐ ๋ฐฉ์‹์˜ ์ฐจ์ด์  ๋™๊ธฐ(synchronous) ๋ฐฉ์‹ ์š”์ฒญ๊ณผ ๊ฒฐ๊ณผ๊ฐ€ ๋™์‹œ์— ์ผ์–ด๋‚˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์š”์ฒญ์„ ๋ณด๋‚ธ ํ›„ ์‘๋‹ต์„ ๋ฐ›์•„์•ผ ๋‹ค์Œ ๋™์ž‘์ด ์ง„ํ–‰๋œ๋‹ค. ์š”์ฒญ๊ณผ ๊ฒฐ๊ณผ๊ฐ€ ํ•œ ์ž๋ฆฌ์— ๋™์‹œ์— ๋‚˜ํƒ€๋‚˜๋Š” ๊ฒƒ์œผ๋กœ ์‚ฌ์šฉ์ž๊ฐ€ ์„œ๋ฒ„๋กœ ์š”์ฒญ์„ ๋ณด๋ƒˆ์„ ๊ฒฝ์šฐ ์š”์ฒญ์— ๋Œ€ํ•œ ์‘๋‹ต์„ ๋ฆฌํ„ด๋ฐ›๊ธฐ ์ „๊นŒ์ง€๋Š” ๋‹ค๋ฅธ ๊ฒƒ์„ ํ•˜์ง€ ๋ชปํ•˜๊ณ  ๊ธฐ๋‹ค๋ ค์•ผ ํ•œ๋‹ค. ํŠน์ • ํ”„๋กœ๊ทธ๋žจ์„ ๊ตฌ๋™์‹œํ‚ค๋Š” ๋ฐ ์‹œ๊ฐ„์ด 5๋ถ„ ์†Œ์š”๋œ๋‹ค๊ณ  ํ•˜๋ฉด, ์ด ํ”„๋กœ๊ทธ๋žจ์ด ๊ตฌ๋™๋˜๋Š” 5๋ถ„๋™์•ˆ ์ปดํ“จํ„ฐ๋Š” ๋‹ค๋ฅธ ํ”„๋กœ๊ทธ๋žจ์„ ๋™์ž‘์‹œํ‚ค์ง€ ๋ชปํ•˜๊ณ , ๊ตฌ๋™๋˜๊ธฐ๋ฅผ ๊ธฐ๋‹ค๋ ค์•ผ ํ•œ๋‹ค. ์žฅ์  : ์„ค๊ณ„๊ฐ€ ๊ฐ„๋‹จํ•˜๊ณ , ์ง๊ด€์ ์ด๋‹ค. ๋‹จ์  : ์š”์ฒญ์— ๋Œ€ํ•œ ๊ฒฐ๊ณผ๊ฐ€ ๋ฐ˜ํ™˜๋˜๊ธฐ ์ „๊นŒ์ง€ ๋Œ€๊ธฐํ•ด์•ผ ํ•œ๋‹ค. ๋น„๋™๊ธฐ(Asynchronous) ๋ฐฉ์‹ ์š”์ฒญ๊ณผ ๊ฒฐ๊ณผ๊ฐ€ ๋™์‹œ์— ์ผ์–ด๋‚˜์ง€ ์•Š๋Š” ๋ฐฉ์‹์œผ๋กœ ์š”์ฒญ๊ณผ ๊ฒฐ๊ณผ๊ฐ€ ๋™์‹œ์— ์ผ์–ด๋‚˜์ง€ ์•Š๋Š”๋‹ค. ์š”์ฒญํ•œ ๊ณณ์— ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜ํƒ€๋‚˜์ง€ ์•Š์œผ๋ฉฐ, .. 2022. 5. 4.
[JAVA] ๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ ๋ฐฉ๋ฒ• - Thread JAVA์—์„œ ๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•ด ์Šค๋ ˆ๋“œ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ๋‹ค๋ฅธ ์„œ๋ฒ„๋กœ ์š”์ฒญ์„ ๋ณด๋‚ผ ๋•Œ ๋น„๋™๊ธฐ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์ž‘์„ฑํ•˜๋ฉด ๋œ๋‹ค. public void request() { Thread thread = new Thread(new Runnable() { @Override public void run() { //์ฝ”๋“œ ์ž‘์„ฑ } }); thread.start(); } ํ•˜์ง€๋งŒ ๋ณ‘๋ ฌ์ž‘์—… ์ฒ˜๋ฆฌ๋Ÿ‰์ด ๋งŽ์•„์ง€๋ฉด ์„ฑ๋Šฅ์ด ์ €ํ•˜๋˜๋Š”๋ฐ, ์ด๋ฅผ ๋ง‰๊ธฐ ์œ„ํ•ด์„œ ์Šค๋ ˆ๋“œ ํ’€์„ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค. ์Šค๋ ˆ๋“œํ’€์€ ์Šค๋ ˆ๋“œ ๊ฐœ์ˆ˜๋ฅผ ๋ฏธ๋ฆฌ ์ •ํ•ด ๋†“๊ณ , ์ž‘์—… ํ์— ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ์„ ๋ฏธ๋ฆฌ ์ƒ์„ฑํ•ด ๋†“์€ ์Šค๋ ˆ๋“œ๋“ค์—๊ฒŒ ํ• ๋‹นํ•˜๋Š” ๋ฐฉ์‹์ด๋‹ค. JDK 1.5๋ถ€ํ„ฐ๋Š” java.util.concurrent Package์— ExecutorService ์ธํ„ฐํŽ˜์ด์Šค์™€ Ex.. 2022. 4. 27.
[JAVA] java.lang.NoSuchMethodError: org.apache.logging.log4j.Logger.error(Ljava/lang/String;Ljava/lang/Object;)V] ๊ณตํ†ต ์‚ฌ์šฉ๋˜๋Š” ๊ธฐ๋Šฅ์„ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ๋งŒ๋“ค์—ˆ๋‹ค. ์ด ๊ณตํ†ต ๊ธฐ๋Šฅ์„ ๋ชจ์•„๋‘” ํ”„๋กœ์ ํŠธ์˜ pom.xml์—๋Š” log4j-api.jar๋ฅผ ์„ ์–ธํ•˜์˜€๊ณ , ์ด๋ฅผ ์ด์šฉํ•˜์—ฌ log๋ฅผ ๋‚จ๊ฒผ๋‹ค. ex) log.error("์—๋Ÿฌ ๋ฐœ์ƒ");, log.debug("์ฒ˜๋ฆฌ ์™„๋ฃŒ"); ํ•˜์ง€๋งŒ ๋‹ค๋ฅธ ํ”„๋กœ์ ํŠธ์—์„œ ๊ณตํ†ต ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋‹ˆ ๋กœ๊ทธ๋ฅผ ๋‚จ๊ธฐ๋Š” ๋ถ€๋ถ„์—์„œ ์•„๋ž˜์™€ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€๋‹ค. Servlet.service() for servlet [appServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: org.apache.logging.log4j.Logger.error(Lja.. 2022. 3. 25.
[JAVA] HttpClient ๋กœ๊ทธ ๋‚จ๊ธฐ๊ธฐ, ๋กœ๊ทธ ๋ ˆ๋ฒจ ์ œ์–ดํ•˜๊ธฐ org.apache.http.client.HttpClient ์˜ ๋กœ๊ทธ๊ฐ€ ๋กœ๊น…๋˜์ง€ ์•Š์•„ ์‚ดํŽด๋ณด๋‹ˆ JCL๊ณผ slf4j์˜ ๋ธŒ๋ฆฟ์ง€ ์—ญํ• ์„ ํ•˜๋Š” 'jcl-over-slf4j' ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ๋น ์ ธ์žˆ์—ˆ๋‹ค. ์ด ๋ถ€๋ถ„์— ๋Œ€ํ•œ ์ž์„ธํ•œ ์„ค๋ช…์€ ์ด ๋ธ”๋กœ๊ทธ๋ฅผ ์ฐธ๊ณ ํ•˜๊ธฐ! https://dololak.tistory.com/635 pom.xml์— jcl-over-slf4j ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ์—ˆ๊ณ  org.slf4j jcl-over-slf4j ${slf4j.version} log4j2๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์—ˆ๊ธฐ์— log4j2.xml์— ์•„๋ž˜์™€ ๊ฐ™์ด ์ถ”๊ฐ€ํ•ด์ฃผ์—ˆ๋‹ค. 2022. 3. 25.
[JAVA] jackson -JsonInclude ์†์„ฑ (null, empty๋“ฑ์˜ ๋ฐ์ดํ„ฐ ์ œ์™ธํ•˜๊ธฐ) VO๊ฐ์ฒด๋ฅผ JSON์œผ๋กœ ๋ณ€ํ™˜ํ•  ๋•Œ ํฌํ•จ๋˜๋ฉด ์•ˆ๋˜๋Š” ๋ณ€์ˆ˜์— @JsonIgnore ์–ด๋…ธํ…Œ์ด์…˜์„ ์„ ์–ธํ•˜์—ฌ JSON์— ํฌํ•จ๋˜์ง€ ์•Š๋„๋ก ํ•  ์ˆ˜ ์žˆ๋‹ค. ํ•˜์ง€๋งŒ ์ƒํ™ฉ์— ๋”ฐ๋ผ json ํฌํ•จ ์—ฌ๋ถ€๊ฐ€ ๋‹ฌ๋ผ์ง€๋Š” ๊ฒฝ์šฐ ์•„๋ž˜์™€ ๊ฐ™์€ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค. ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); //null์ธ ๋ฐ์ดํ„ฐ๋ฅผ ์ œ์™ธํ•˜๊ณ  json ์ƒ์„ฑ mapper.writeValueAsString(testVO); VO์— default๋กœ ์ ์šฉํ•˜๋ ค๋ฉด VO Class์— @JsonInclude ์–ด๋…ธํ…Œ์ด์…˜์„ ์„ ์–ธํ•˜๋ฉด ๋œ๋‹ค. @JsonInclude(JsonInclude.Include.NON_NULL) .. 2022. 3. 11.
[Spring Framework] CORS ์ ์šฉํ•˜๊ธฐ - @CrossOrigin, <mvc:cors>, Filter CORS๋ž€? test2.com:8080์‚ฌ์ดํŠธ์™€ test.com:18080 ์‚ฌ์ดํŠธ๋Š” ๋„๋ฉ”์ธ๊ณผ ํฌํŠธ๊ฐ€ ๋‹ค๋ฅด๋‹ค. ๋”ฐ๋ผ์„œ test.com:18080์—์„œ test2.com:8080์‚ฌ์ดํŠธ๋กœ ์š”์ฒญ์„ ๋ณด๋‚ด๊ฒŒ ๋˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ์—๋Ÿฌ๋ฅผ ๋งŒ๋‚  ์ˆ˜ ์žˆ๋‹ค. Access to XMLHttpRequest at 'http://domain1:8080/xxxxx' from origin 'http://test.com:18080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. http://localhost:8080/test/1 ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋น„๊ตํ•ด๋ณด๋ฉด URL ์ถœ์ฒ˜ ๋น„๊ณ  http://local.. 2022. 3. 11.
[JAVA] The method getRealPath(String) from the type ServletRequest is deprecated WEB-INF ๊ฒฝ๋กœ์— ์žˆ๋Š” ํŠน์ • ํŒŒ์ผ์˜ ์ ˆ๋Œ€๊ฒฝ๋กœ๋ฅผ ๊ฐ€์ ธ์˜ค๋ ค๊ณ  ์•„๋ž˜์™€ ๊ฐ™์ด ์ž‘์„ฑํ–ˆ๋Š”๋ฐ 'The method getRealPath(String) from the type ServletRequest is deprecated'๋ผ๋Š” ๊ฒฝ๊ณ  ๋ฌธ๊ตฌ๊ฐ€ ํ‘œ์‹œ๋˜์—ˆ๋‹ค. request.getRealPath("/WEB-INF/xxx/xxx.txt"); ํ•ด๊ฒฐ๋ฐฉ๋ฒ• request.getSession().getServletContext().getRealPath("/WEB-INF/xxx/xxx.txt"); jsp์—์„  ์•„๋ž˜์™€ ๊ฐ™์ด ๋ฐ”๊ฟ”์ฃผ๋ฉด ๋œ๋‹ค! application.getRealPath("/WEB-INF/xxx/xxx.txt"); 2022. 3. 11.
728x90
๋ฐ˜์‘ํ˜•