thread-safe멀티스레드 프로그램은 스레드 간 공유하여 사용하는 data가 있을 때, 스레드 동기화가 되지 않는다면 data의 신뢰성을 보장할 수 없으므로 신경 써야한다. 이를 thread-safe하다고 한다.이를 위해서 java에서는 스레드 동기화를 가능하게 하는 synchronized 기능을 제공한다. synchronized여러 스레드가 한 개의 자원을 사용하고자 할 때 데이터를 점유한 스레드를 제외한 나머지는 데이터에 접근을 못하도록 막는 것을 말한다. 변수와 함수에 사용할 수 있다.public synchronized void method() {}private Object obj = new Object();public void exMethod() {synchronized(obj) {}} Thr..
RestTemplate 으로 POST 전송시에 파라미터(application/x-www-form-urlencoded)로 메시지 보내기 Map으로 httpbody를 구성할 경우 아래와 같은 에러가 발생한다.No HttpMessageConverter for java.util.HashMap and content type "application/x-www-form-urlencoded"HashMap은 urlencoded에는 사용할 수 없다는 모양이다 왜죠...이 경우 Multivaluemap을 사용하여 바디를 구성할 경우 전송이 된다. 웃긴게 값을 put을 하면 에러가 나고 add를 해야한다... 왜죠... // 2. make http body MultiValueMap body = new..
양식 데이터 form의 'file'이라는 이름으로 전송되기 때문에 아규먼트도 'file'을 지켜주어야 한다. @RestController @RequestMapping("/excel") public class ExcelController { @Resource ExcelService service; @RequestMapping("/shipment") public void saveExcel(MultipartFile file) throws Exception { // 정상 @RequestMapping("/shipment") public void saveExcel(MultipartFile excelFile) throws Exception { // NPE 발생
String a = ""; Integer b = Integer.valueOf(a); System.out.println(b); // null int c = Integer.valueOf(a); System.out.println(c); // 0 String aa = null; Integer bb = Integer.valueOf(aa); System.out.println(bb); // null int cc = Integer.valueOf(aa); System.out.println(cc); // 0
String str1 = new String(niceAuthResp.getName().getBytes() "utf-8"); String str2 = new String(niceAuthResp.getName().getBytes() "euc-kr"); String str3 = new String(niceAuthResp.getUtf8_name().getBytes() "utf-8"); String str4 = new String(niceAuthResp.getUtf8_name().getBytes() "euc-kr"); String str5 = new String(niceAuthResp.getName()); String str6 = new String(niceAuthResp.getUtf8_name()); byte[..
public class C{ private CCC ccc () = new CCC; private CCC ddd () = new CCC; private c ( AAA a, BBB b) { ccc = new CCC(a); ddd = new CCC(b); } class CCC(){ private String a(); private CCC(AAA A ){ this.a = A.a; ... } private CCC(BBB b ){ this.a = B.a; ... } } } ..... C c = new C(a,b); c.ccc.getA(); c.ddd.getB();