google-http-client请求处理超时

时间:2018-07-31 11:18:06

标签: java google-api google-http-client

        HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        HttpRequestFactory requestFactory = httpTransport.createRequestFactory();

        long begin = System.currentTimeMillis();
        HttpRequest request = requestFactory.buildPostRequest(
                new GenericUrl(RecommendationEngineConstant.MAKE_RECOMMENDATION_PREDICT),
                new JsonHttpContent(new JacksonFactory(), json));
        request.setConnectTimeout(10000);
        request.setReadTimeout(10000);

        HttpResponse response = request.execute();
        long time = System.currentTimeMillis() - begin;
        if (time >= 3000) {
            logger.error(">> returned in " + time + "ms, and predict json = " + json.toPrettyString());
        }

上面的代码中的“时间”超过了3秒,但是使用CURL请求API的返回非常快,这种情况约占20%,请问是什么问题?

0 个答案:

没有答案