有没有大佬知道这个是怎么回事,我更新数据,7条以下的都可以,以上就连接超时了,有知道是什么原因的么

  @Override
    public void setTingLogisticsNumber(SetTingLogisticsNumberReq request, SetTingLogisticsNumberResp response) {

        int success = 0;
        int failure = 0;
        if (request.expressId == 1) {
            String regex = "(^[A-Z]{2}[0-9]{9}[A-Z]{2}$)";
            boolean flag = Pattern.matches(regex, request.startNo);
            if (flag) {
                Long ref = tradeMapper.selectExpressShipNo(request.startNo);
                if (ref == 0) {
                    List<String> expressShipNoList = CreateEMS(request.startNo, request.tradeIdList.size());
                    for (int i = 0; i < expressShipNoList.size(); i++) {
                        String expressShipNo = expressShipNoList.get(i);
                        String tradeId = request.getTradeIdList().get(i);
                        try {
                            tradeMapper.setTingLogisticsNumber(expressShipNo, Long.parseLong(tradeId));
                            success++;
                        } catch (NumberFormatException e) {
                            LOG.error(e);
                            failure++;
                        }
                    }
                    response.errorCode = success;
                    response.errorMessage = "设置成功" + success + "条," + "失败" + failure + "条";
                } else {
                    response.errorCode = 0;
                    response.errorMessage = "快递单号已存在!请重新输入";
                }
            } else {
                response.errorCode = 0;
                response.errorMessage = "格式不正确!请重新输入";
            }

        }

我传的tradeList的长度为7以下都可以,以上就都连接超时,

  @Test
    public void setTingLogisticsNumber() {
        SetTingLogisticsNumberReq request = new SetTingLogisticsNumberReq();
        request.session = new UserSession("a", "b");
        List<String> list = new ArrayList<>();
        list.add("171104618795");
        list.add("171104618796");
        list.add("171104618798");
//        list.add("171104618799");
//        list.add("171104618945");
//        list.add("171104618946");
        list.add("171104618947");
        list.add("171104618948");
        list.add("171104618949");
        list.add("171104618950");

        request.expressId = 1;
        request.startNo = "EC912111847CS";
        request.tradeIdList = list;
        Holder<SetTingLogisticsNumberResp> response = new Holder<SetTingLogisticsNumberResp>();
        Map<String, String> context = new HashMap<String, String>();
        context.put("IP", "192.168.1.1");
        int ret = proxy.setTingLogisticsNumber(request, response, context);
        Assert.assertEquals(0, ret);
    }

这是我的测试用例。不管注释其中那三条都可以成功

是不是屏幕只能显示7条数据

会不会跟你的数据库连接池的设置有关

程序有不少地方可以优化:比如Regex可以考虑缓存,看不到trademapper的实现,估计问题出在那里。可能有N+1 SELECT的设计问题
后台连的什么数据库或其他系统?

数据或程序有问题,那3条数据产生死循环或者exception.

  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="org.gjt.mm.mysql.Driver" />
        <property name="url"
            value="jdbc:mysql://${datasource.cloudx.host}:${datasource.cloudx.port}/${datasource.cloudx.database}?useUnicode=true&amp;characterEncoding=UTF-8&amp;zeroDateTimeBehavior=convertToNull" />
        <property name="username" value="${datasource.cloudx.user}" />
        <property name="password" value="${datasource.cloudx.password}" />
        <property name="initialSize" value="5" />
        <property name="maxActive" value="50" />
        <property name="maxIdle" value="50" />
        <property name="minIdle" value="5" />
        <property name="maxWait" value="30000" />
        <property name="validationQuery" value="SELECT 1+1" />
        <property name="defaultAutoCommit" value="false" />
    </bean>

怀疑是你连接没有释放,你tradeMapper.setTingLogisticsNumber方法的代码看下呢

图片说明


    @Override
    public void setTingLogisticsNumber(SetTingLogisticsNumberReq request, SetTingLogisticsNumberResp response) {

        int success = 0;
        int failure = 0;
        if (request.expressId == 1) {
            String regex = "(^[A-Z]{2}[0-9]{9}[A-Z]{2}$)";
            boolean flag = Pattern.matches(regex, request.startNo);
            if (flag) {
                Long ref = tradeMapper.selectExpressShipNo(request.startNo);
                if (ref == 0) {
                    List<String> expressShipNoList = CreateEMS(request.startNo, request.tradeIdList.size());
                    for (int i = 0; i < expressShipNoList.size(); i++) {
                        String expressShipNo = expressShipNoList.get(i);
                        String tradeId = request.getTradeIdList().get(i);
                        LOG.debug(expressShipNo+":"+tradeId+"快递单号,交易编号"+i);
                        try {
                            tradeMapper.setTingLogisticsNumber(expressShipNo, Long.parseLong(tradeId));
                            success++;
                        } catch (NumberFormatException e) {
                            LOG.error(e);
                            failure++;
                        }
                    }
                    response.errorCode = success;
                    response.errorMessage = "设置成功" + success + "条," + "失败" + failure + "条";
                } else {
                    response.errorCode = 0;
                    response.errorMessage = "快递单号已存在!请重新输入";
                }
            } else {
                response.errorCode = 0;
                response.errorMessage = "格式不正确!请重新输入";
            }

        } else if (request.expressId == 2) {
            String regex = "(^[0-9]{12}$)";
            boolean flag = Pattern.matches(regex, request.startNo);
            if (flag) {
                Long ref = tradeMapper.selectExpressShipNo(request.startNo);
                if (ref == 0) {
                    List<String> expressShipNoList = CreateSF(request.startNo, request.tradeIdList.size());
                    for (int i = 0; i < expressShipNoList.size(); i++) {
                        String expressShipNo = expressShipNoList.get(i);
                        String tradeId = request.getTradeIdList().get(i);
                        try {
                            tradeMapper.setTingLogisticsNumber(expressShipNo, Long.parseLong(tradeId));
                            success++;
                        } catch (NumberFormatException e) {
                            LOG.error(e);
                            failure++;
                        }
                    }
                    response.errorCode = success;
                    response.errorMessage = "设置成功" + success + "条," + "失败" + failure + "条";
                } else {
                    response.errorCode = 0;
                    response.errorMessage = "快递单号已存在!请重新输入";
                }
            } else {
                response.errorCode = 0;
                response.errorMessage = "格式不正确!请重新输入";
            }
        }

    }





  /**
     * 获取一定数量的EMS快递单号
     *
     * @param EMSNo
     * @param num
     * @return
     */
    public static List<String> CreateEMS(String EMSNo, int num) {

        List<String> EMSres = new ArrayList<String>();

        String fri;
        int res, num3, num4, num5, num6, num7, num8, num9, num0, mid;

        fri = EMSNo.substring(2, 10);
        for (int i = 0; i < num; i++) {
            num3 = Integer.parseInt(fri.substring(0, 1));
            num4 = Integer.parseInt(fri.substring(1, 2));
            num5 = Integer.parseInt(fri.substring(2, 3));
            num6 = Integer.parseInt(fri.substring(3, 4));
            num7 = Integer.parseInt(fri.substring(4, 5));
            num8 = Integer.parseInt(fri.substring(5, 6));
            num9 = Integer.parseInt(fri.substring(6, 7));
            num0 = Integer.parseInt(fri.substring(7, 8));

            mid = 8 * num3 + 6 * num4 + 4 * num5 + 2 * num6 + 3 * num7 + 5 * num8 + 9 * num9 + 7 * num0;
            res = 11 - (mid) % (11);

            if (res == 10)
                res = 0;
            if (res == 11)
                res = 5;
            // 1、此处长度不足时前面需要根据情况补0 2、起始的EC 和CS请自行截取后拼接
            EMSres.add("EC" + fri + String.valueOf(res) + "CS");
            fri = String.valueOf(Long.valueOf(fri) + 1);

        }
        return EMSres;
    }

    /**
     * 获取一定数量的顺丰快递单号
     *
     * @param ShunFengNo
     * @param num
     * @return
     */
    public static List<String> CreateSF(String ShunFengNo, int num) {

        List<String> ShunFengres = new ArrayList<String>();

        String fri, Nfri, Yuandanhao;
        int num1, num2, num3, num4, num5, num6, num7, num8, num9, num10, num11, num12, Nnum1, Nnum2, Nnum3, Nnum4,
                Nnum5, Nnum6, Nnum7, Nnum8, Nnum9, Nnum10, Nnum11, Nnum12, mid;

        fri = ShunFengNo.substring(0, 11);
        ShunFengres.add(ShunFengNo);
        Yuandanhao = ShunFengNo;
        System.out.println(Yuandanhao.substring(0, 1));

        for (int i = 0; i < num - 1; i++) {
            Nfri = String.valueOf(Long.valueOf(fri) + 1);

            num1 = Integer.parseInt(Yuandanhao.substring(0, 1));
            num2 = Integer.parseInt(Yuandanhao.substring(1, 2));
            num3 = Integer.parseInt(Yuandanhao.substring(2, 3));
            num4 = Integer.parseInt(Yuandanhao.substring(3, 4));
            num5 = Integer.parseInt(Yuandanhao.substring(4, 5));
            num6 = Integer.parseInt(Yuandanhao.substring(5, 6));
            num7 = Integer.parseInt(Yuandanhao.substring(6, 7));
            num8 = Integer.parseInt(Yuandanhao.substring(7, 8));
            num9 = Integer.parseInt(Yuandanhao.substring(8, 9));
            num10 = Integer.parseInt(Yuandanhao.substring(9, 10));
            num11 = Integer.parseInt(Yuandanhao.substring(10, 11));
            num12 = Integer.parseInt(Yuandanhao.substring(11, 12)); // 12位没有,就11位,添加两个变量存储原始直ֱ

            Nnum1 = Integer.parseInt(Nfri.substring(0, 1));
            Nnum2 = Integer.parseInt(Nfri.substring(1, 2));
            Nnum3 = Integer.parseInt(Nfri.substring(2, 3));
            Nnum4 = Integer.parseInt(Nfri.substring(3, 4));
            Nnum5 = Integer.parseInt(Nfri.substring(4, 5));
            Nnum6 = Integer.parseInt(Nfri.substring(5, 6));
            Nnum7 = Integer.parseInt(Nfri.substring(6, 7));
            Nnum8 = Integer.parseInt(Nfri.substring(7, 8));
            Nnum9 = Integer.parseInt(Nfri.substring(8, 9));
            Nnum10 = Integer.parseInt(Nfri.substring(9, 10));
            Nnum11 = Integer.parseInt(Nfri.substring(10, 11));

            if ((Nnum9 - num9 == 1) && ((num9) % (2) == 1)) {
                if (num12 - 8 >= 0)
                    Nnum12 = num12 - 8; // -8
                else
                    Nnum12 = num12 - 8 + 10;
            } else if ((Nnum9 - num9 == 1) && ((num9) % (2) == 0)) {
                if (num12 - 7 >= 0)
                    Nnum12 = num12 - 7; // -7
                else
                    Nnum12 = num12 - 7 + 10;
            } else {
                if (((num10 == 3) || (num10 == 6)) && (num11 == 9)) {
                    if (num12 - 5 >= 0)
                        Nnum12 = num12 - 5; // -5
                    else
                        Nnum12 = num12 - 5 + 10;
                } else if (num11 == 9) {
                    if (num12 - 4 >= 0)
                        Nnum12 = num12 - 4; // -4
                    else
                        Nnum12 = num12 - 4 + 10;
                } else {
                    if (num12 - 1 >= 0)
                        Nnum12 = num12 - 1; // -1
                    else
                        Nnum12 = num12 - 1 + 10;
                }
                ;
            }
            ;
            ShunFengres.add(Nfri + String.valueOf(Nnum12));
            Yuandanhao = Nfri + String.valueOf(Nnum12);
            fri = String.valueOf(Long.valueOf(fri) + 1);
        }
        return ShunFengres;
    }








        public interface TradeMapper {

    List<TradeEntity> listTrade(@Param("sqlStu") String sqlStu);

    Long totalCount(@Param("sqlStu") String sqlStu);

    List<TradeEntity> printDeliveryList(@Param("tradeIds") List<String> tradeIds);

    List<TradeEntity> printExpressList(@Param("tradeIds") List<String> tradeIds);

    int updateTradeSysStatusAndPrintList(@Param("tradeIds") List<String> tradeIds);

    int updatePrintExpress(@Param("tradeIds") List<String> tradeIds);

    int setRemark(@Param("depotMessage") String depotMessage, @Param("tradeIds") List<String> tradeIds);

    int returnCustomerService(@Param("abnormalMsg") String abnormalMsg, @Param("tradeIds") List<String> tradeIds);

    int batchUpdateExpress(@Param("expressId") String expressId, @Param("tradeIds") List<String> tradeIds,
            @Param("depotMessage") String depotMessage);

    int returnPrinting(@Param("tradeIds") List<String> tradeIds);

    int printingComplete(@Param("tradeIds") List<String> tradeIds);

    int oneButtonDelivery(@Param("tradeIds") List<String> tradeIds);

    Long getWaitingDelivery();

    Long getWaitingPrint();

    Long selectExpressShipNo(@Param("startNo") String startNo);

    int setTingLogisticsNumber(@Param("expressShipNo") String expressShipNo, @Param("tradeId") Long tradeId);

    List<TradeEntity> getUnscannedList(@Param("tradeMallStatus") int tradeMallStatus,
            @Param("tradeSysStatus") int tradeSysStatus, @Param("isCheck")short isCheck);

    TradeEntity getUnscanndeListByExpressShipNo(String expressShipNo);

    Long getTradeIdByExpressShipNo(String expressShipNo);

}

序有不少地方可以优化:比如Regex可以考虑缓存,看不到trademapper的实现,估计问题出在那里。可能有N+1 SELECT的设计问题
后台连的什么数据库或其他系统?

建议你写个延时器,一秒post一次,看看会不会出错,很有可能是负载问题。