Java for WebService Call Disconnect中等效的setTimeout是什么?

时间:2016-12-20 06:52:09

标签: java web-services settimeout

我正在使用java中的webService调用它运行良好,但我需要SetTimout进行连接。以下是我的要求。

  • 我需要设置的最长时间是2分钟。如果达到该时间,连接应该断开。
  

这是我的连接建立代码,得到回复。

ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
            String urlParameters = ow.writeValueAsString(something);
            urlParameters = "{ \"something\":" + urlParameters + "}" ;
            byte[] postData       = urlParameters.getBytes( StandardCharsets.UTF_8 );
            int    postDataLength = postData.length;
            String request        = "http://something.com";
            url = new URL( request );
            postConnection = (HttpURLConnection) url.openConnection();    
            postConnection.setDoOutput( true );
            postConnection.setInstanceFollowRedirects( false );
            postConnection.setRequestMethod( "POST" );
            postConnection.setRequestProperty( "Content-Type", "application/json"); 
                DataOutputStream wr = new DataOutputStream( postConnection.getOutputStream());
                    wr.write( postData );
                    wr.flush();
                    wr.close();


                BufferedReader in = new BufferedReader(
                        new InputStreamReader(postConnection.getInputStream()));

Thanx寻求帮助

0 个答案:

没有答案