> "Code:
> Runtime r = Runtime.getRuntime();
> Process p = r.exec(" java myClass ");
>
> Works but is awfully slow. Any insights? "
Java's exec() can be a terrible beast if you do not properly program
the handling of the stdio streams. I am not sure if this is your problem
specifically, but it could be. Here is a version of exec() which handles
the stdio properly:
http://www.gjt.org/jcvslet/ice/com/ice/jcvsii/ExecViewer.java
You will note this is a Thread, and you should pay most attention to the
run() method. The class is supporting jCVS's ExecViewer, which allows users
to click on files they wish to open/edit, and it then invokes exec() for
that purpose, say, for instance 'vi $file'. The important thing to note is
that a thread is required for each stdio stream, otherwise you will get
slow performance and even deadlock.
> Why not use something like:
>
> String[] args={"a","b"};
> com.abc.ClassName.main(args);
>
> instead? Then you don't have to fork off a new process.
I agree 100%. Exec() is a terrible replacement for direct method calls.
tim.