데이터 처리 이후 웹에는 결과를 보내고 background  에서 몇초 간격으로 계속 조회를 시도 해야하는 경우

 

serviceImpl.java 에 @Async 를 추가 하고 작업

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
@Override
    @Async
    public void chkGetOrderStatusAsync(String orderSubNum, String transactionId, String userId) throws Exception{
        
        //비동기 실행
        //get Order Status 호출하여 accepted 혹은 FAILED 가 뜰때까지 15초 간격으로 실행 최대 20번
        boolean flag = true;
        int cnt = 0;
        try{
            while(flag){
                
                JSONParser jsonParser = new JSONParser();
                String getOrderStausRes = APIUtil.getOrderStatus(transactionId);
                System.out.println("==== get Order Status API Async " + orderSubNum + " : " + transactionId + " (" + cnt + ") ====");
                System.out.println(getOrderStausRes);
                JSONObject getOrderStatusObj = (JSONObject) jsonParser.parse(getOrderStausRes);
                String status = UxisStringUtil.nullConvert(getOrderStatusObj.get("status"));
                String message = UxisStringUtil.nullConvert(getOrderStatusObj.get("message"));
 
                if(("Order is processing.".equals(message) || "Order is created.".equals(message) ) && cnt < 20){
                    //processing 일 경우 15초 대기 후 재실행
                    flag = true;
                    cnt++;
                    Thread.sleep(15000); //15초 대기
                }else{
                    PwsApiLogVO logVo = new PwsApiLogVO();
                    logVo.setOrderSubNum(orderSubNum);
                    logVo.setTransactionId(transactionId);
                    logVo.setStatus(status);
                    //logVo.setCode(code);
                    logVo.setMessage(message);
                    logVo.setRegistUserId(userId);
                    dao.insertData(logVo);
                    flag = false;
                }
                
            }
        }catch(Exception e){
            System.out.println("++++++ " + orderSubNum + " : " + transactionId + " (" + cnt + ") 실패 ++++++ ");
            e.printStackTrace();
        }
        
        
    }
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

'web > java' 카테고리의 다른 글

[java] 정규식을 이용한 개인정보 마스킹  (0) 2020.04.09
java timestamp  (0) 2020.04.01
java jsonObject 처리  (0) 2020.04.01
엑셀 다운로드시 로딩바 보이게  (0) 2020.03.13

+ Recent posts