Last active
August 29, 2015 14:01
-
-
Save froop/52e9a4da4fde1c3a6e9e to your computer and use it in GitHub Desktop.
[Java] Apache Commons Exec のスレッドセーフ化
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Apache Commons Exec の同時起動できない問題への対策. | |
* 同時に複数が実行開始されると、それら全ての実行完了が一番遅い実行を待ってしまう現象. | |
* 原因は、Runtime#exec() の呼び出しがマルチスレッドで競合しているため. | |
* Runtime の呼び出しを synchronized でロックすることで解消. | |
*/ | |
class ThreadSafeExecutor extends org.apache.commons.exec.DefaultExecutor { | |
@Override | |
protected Process launch(CommandLine command, Map env, File dir) | |
throws IOException { | |
synchronized (ThreadSafeExecutor.class) { | |
return super.launch(command, env, dir); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment