Dig their own pit filled --JVM reported memory overflow

In writing regular tasks, batch operation table data, test data, there are about 100,000, found during testing Paozhaopaozhe memory overflow occurs, and eventually found objects paramList and tmBeanList created not recovered, look through the information, is found not to continue to create objects in a circular reference, or else there count cycles, memory, there are parts of an object reference count, then the cost of memory, so each cycle had completed destruction of the object reference (set to null); or declare objects directly vitro cycle for, create objects referenced in the body of the loop, so that only one object reference in memory, each new object, the object reference different points, but only one in memory.

/ ** 
 * regular tasks, XXXX 
 * @author XXX 
 * XXX @date 
 * @version XXX
  * / 
@Component (value = "xxxJob" )
 public  class xxxJob { 

    @Transactional 
    public  void the doService (the Map <String, Object> the scheduleJob) { 
        logger.info ( "----------------------- start timing task, XXXXX ----------" );
         // business logic 
        --- --- omitted service code for ( map <String, Object> Map: List) {
             the try {
                 --- --- omitted service code
        
                List<Map<String, Object>> tmBeanList = tMemberRfmDao.queryBeanForMap(tmr);
                List<Map<String, Object>> paramList = new ArrayList<>();
                if (!CollectionUtils.isEmpty(tmBeanList)) {
                    ---省略业务代码---
                    for (Map<String, Object> member : tmBeanList) {
                        String memberId = (String) member.get("member_id");
                        Map<String, Object> tml = new HashMap<>();
                        ---省略业务代码---
                        tml.put("data_status", 0);
                        tml.put("create_time",
                                DateUtils.getDate("yyyy-MM-dd HH:mm:ss"));
                        tml.put("update_time",
                                DateUtils.getDate("yyyy-MM-dd HH:mm:ss"));
                        paramList.add(tml);
                        if(paramList.size() == INT_TWO_THOUSAND){
                            tMemberLabelDao.saveBatch(paramList);
                            paramList.clear();
                        }
                    }
                    if(paramList.size() != 0){
                        tMemberLabelDao.saveBatch (paramList); 
                    } paramList
                     = null ; 
                    tmBeanList = null;
                     --- log --- 
                } the else {
                     --- log --- 
                } 
            } the catch (Exception E) {
                 --- --- exception 
            } 
        } 
        logger.info ( "----------------------- end timing task, XXXX" ); 
    } 
} 
Note (objects declared outside the loop, the loop body creating an object reference, Object references to different objects Object):
Object = null Object;
for (int I = 0; I <= COUNT; I ++) {
Object = new new Object ();
}

 

Guess you like

Origin www.cnblogs.com/huangrenhui/p/11365141.html