この質問とは少し関係のない他の大量のデータ処理に加えて、特定の Web アドレスに多数の XML ドキュメントを POST するプログラムを Java で作成しています。唯一の問題は、約 90,000 レコードを処理する予定であることです。XML 文書を POST する場合、各レコードには約 10 秒かかり、そのうち 9 秒は POST 後にサーバーからの応答を受信するために使用されます。
私の質問は: データを Web サーバーに POST し、サーバーの応答を無視して時間を節約する方法はありますか?
問題を引き起こしているコードの一部を次に示します。システム タイマーによると、「writer.close」から「con.getResponseCode()」に移行するのに約 9 秒かかります。
URL url = new URL(TargetURL);
con = (HttpsURLConnection) url.openConnection();
//Login with given credentials
String login = (Username)+":"+(Password);
String encoding = new sun.misc.BASE64Encoder().encode(login.getBytes());
con.setRequestProperty ("Authorization", "Basic " + encoding);
// specify that we will send output and accept input
con.setRequestMethod("POST");
con.setDoInput(true);
con.setDoOutput(true);
con.setConnectTimeout(20000) ; // long timeout, but not infinite
con.setReadTimeout(20000);
con.setUseCaches (false);
con.setDefaultUseCaches (false);
// tell the web server what we are sending
con.setRequestProperty ( "Content-Type", "text/xml" );
OutputStreamWriter writer = new OutputStreamWriter( con.getOutputStream() );
writer.write(data);
writer.flush();
writer.close();
//****This is our problem.*****//
int result = con.getResponseCode();
System.err.println( "\nResponse from server after POST:\n" + result );