JavaでRuntime.getRuntime().execを使用しています。
このRuntime.getRuntime().execは使用後にプロセスを開放しないと
リソースリークを引き起こすということで、
綺麗に閉じたいのですが、その件で質問です。
Process process = null; try { process = Runtime.getRuntime().exec("someone_command"); process.waitFor(); } finally { if(process != null) { process.getErrorStream().close(); process.getInputStream().close(); process.getOutputStream().close(); process.destroy(); } }
Runtime.getRuntime().execでは
使用していなくても、用意されたストリームをcloseして、
最後にdestroyする必要があるという所までは理解しています。
ここで本題です。
このストリームをcloseする順番なのですが、
何か決まりがあるのでしょうか?
例えば、「getErrorStreamを使ったなら、最初にそれをcloseする」、
「getInputStream、getOutputStream、getErrorStreamの順」
といった決まりごとがあるのでしょうか?
ご存知の方、ご回答どうぞよろしくお願いします。
あなたの回答
tips
プレビュー