zoukankan      html  css  js  c++  java
  • Hibernate 一次查询分多次返回 避免内存溢出

        public void grpcGpioDevice(StreamObserver<NI_GetAllDeviceListResponse> responseObserver,
                Map<String, VsGrpc> vcuMap) {
            Session session = null;
            final StringBuffer sb = new StringBuffer("select name,vs_id,"
                    + "description,direction,device_id,vx_external_id from EMS_GPIO_DEVICE ");
            try {
                session = getSession();
                Query query = session.createSQLQuery(sb.toString()).setFetchSize(grpcRspNumber);
                ScrollableResults results =  query.scroll();
                List<GpioDevice> gpioList = new ArrayList<>();
                
                while(results.next()) {
                    Object[] obj = results.get();
                    GpioDevice gd = new GpioDevice();
                    gd.setName(obj[0] == null ?"":obj[0].toString());
                    gd.setVsId(obj[1] == null ?"":obj[1].toString());
                    gd.setDescription(obj[2] == null ?"":obj[2].toString());
                    gd.setDirection(obj[3] == null ?0:Integer.parseInt(obj[3].toString()));
                    gd.setDeviceId(obj[4] == null ?"":obj[4].toString());
                    gd.setVxExternalId(obj[5] == null ?"":obj[5].toString());
                    gpioList.add(gd);
                    if(gpioList.size()==grpcRspNumber) {
                        NI_GetAllDeviceListResponse.Builder response = NI_GetAllDeviceListResponse.newBuilder();
                        grpcFlowResult.getAiAoDiDoInfo(null, gpioList, vcuMap, "DIDO", response);
                        grpcFlowResult.result(response, responseObserver);
                        gpioList.clear();
                    }
                }
                if(gpioList.size()>0 && gpioList.size()<grpcRspNumber) {
                    NI_GetAllDeviceListResponse.Builder response = NI_GetAllDeviceListResponse.newBuilder();
                    grpcFlowResult.getAiAoDiDoInfo(null, gpioList, vcuMap, "DIDO", response);
                    grpcFlowResult.result(response, responseObserver);
                    gpioList.clear();
                }
            }catch (RuntimeException e) {
                e.printStackTrace();
              } catch (Exception ex) {
                ex.printStackTrace();
            } finally {
                releaseSession(session);
            }
        }
    View Code
  • 相关阅读:
    如何解除任务管理器被禁用
    一、JavaScript概述
    001_html基本结构
    postman常见问题记录
    fidder工具使用
    SonarQube工具使用问题汇总
    业余书籍读后感
    jmater常见问题处理
    测试知识记录(更新中)
    HTTP协议
  • 原文地址:https://www.cnblogs.com/acme6/p/10514918.html
Copyright © 2011-2022 走看看