I guess I have to wait();

R

Ramon F Herrera

This is under Windows XP.

I wrote a couple of programs: the first one in C++ does
some number crunching and the other one in Java which
provides an outside loop to execute the *.exe repeatedly.

The source code looks something like this:

for (i = 0; i < 500; i++) {
commandLine = "C:/path/to/number/crunch.exe";
Runtime.getRuntime().exec(commandLine);
}

The problem is that the above approach brings WinXP to
its knees. Coming from Unix, I figured that the OS would
take care of "rationing" the processes and only starting them
when resources were sufficient, instead of choking the CPU
and page file.

In Unix, I would add a 'wait();' after the fork-exec().
From a more general perspective: how can I allow, say 5
processes at at time, before exec'ing the next one?
Should I use threads for this? How?

-Ramon F Herrera
 
Y

Yu SONG

Ramon said:
This is under Windows XP.

I wrote a couple of programs: the first one in C++ does
some number crunching and the other one in Java which
provides an outside loop to execute the *.exe repeatedly.

In Unix, I would add a 'wait();' after the fork-exec().

processes at at time, before exec'ing the next one?
Should I use threads for this? How?

There are few concurrent utils introduced into Java 1.5 (although you
can write your own) and I think they will help you solve your problem.

--
Song

/* E-mail.c */
#define User "Yu.Song"
#define At '@'
#define Warwick "warwick.ac.uk"
int main() {
printf("Yu Song's E-mail: %s%c%s", User, At, Warwick);
return 0;}

Further Info. : http://www.dcs.warwick.ac.uk/~esubbn/
_______________________________________________________
 
G

Gerard Krupa

Ramon F Herrera wrote:
....
The source code looks something like this:

for (i = 0; i < 500; i++) {
commandLine = "C:/path/to/number/crunch.exe";
Runtime.getRuntime().exec(commandLine);
} ....

In Unix, I would add a 'wait();' after the fork-exec().
From a more general perspective: how can I allow, say 5
processes at at time, before exec'ing the next one?
Should I use threads for this? How?


You could use five threads (or J2SE 5.0's useful ThreadPoolExecutor as
suggested in Yu Song's reply) and a producer/consumer model where each
thread starts a process, calls Process.waitFor() to detect termination
and then starts the next process in the queue.

Alternatively a single thread with a busy-wait periodically calling
Process.exitValue() on each process and catching
IllegalThreadStateException to detect still-running processes would also
work (although it relies on the assumption that the processes execute
asynchronously which isn't necessarily valid).

Gerard Krupa
 
A

Andrea Desole

Ramon said:
processes at at time, before exec'ing the next one?
Should I use threads for this? How?

you can use the Process object returned by the exec method. Process has
a wait method, which is what you need. Just build an array of 5
processes, run exec for each element, and then do a loop of wait() on
our array.
 
A

Ann

Andrea Desole said:
you can use the Process object returned by the exec method. Process has
a wait method, which is what you need. Just build an array of 5
processes, run exec for each element, and then do a loop of wait() on
our array.

You can use the "Windows Task Manager" to lower the priority
of the java.exe process to "BelowNormal."
 
D

dar7yl

"Ramon F Herrera" wrote:...
This is under Windows XP.

I wrote a couple of programs: the first one in C++ does
some number crunching and the other one in Java which
provides an outside loop to execute the *.exe repeatedly.

The source code looks something like this:

for (i = 0; i < 500; i++) {
commandLine = "C:/path/to/number/crunch.exe";
Runtime.getRuntime().exec(commandLine);
}

The problem is that the above approach brings WinXP to
its knees. Coming from Unix, I figured that the OS would
take care of "rationing" the processes and only starting them
when resources were sufficient, instead of choking the CPU
and page file.

In Unix, I would add a 'wait();' after the fork-exec().
From a more general perspective: how can I allow, say 5
processes at at time, before exec'ing the next one?
Should I use threads for this? How?


I fail to see why you want more than 1 process at a time in operation.
Obviously, this task is heavily compute-bound, and unless you have more than
1 processor, adding more processes just decreases the efficiency. You
might consider adding a second process if you want to optimize over
storage-access time, but you have to watch again for resource conflict.

Of course, this is a good way of stress-testing WinXP, but just running a
simple word-processor is stress enough for that technology anyway. :)IMHO:)

regards,
Dar7yl
 
R

Ramon F Herrera

Well, I fail to see your one-to-one rule. :)
What I plan to do is try the program with 6 processes, then
with 5, then with 4, all the way to 1 process running at a time.

The magic number of processes will be the one that
finishes the whole job quicker. If it is one -as you predict-
so be it. Maybe it's two or three.

-Ramon
 
A

Ann

Ramon F Herrera said:
Well, I fail to see your one-to-one rule. :)
What I plan to do is try the program with 6 processes, then
with 5, then with 4, all the way to 1 process running at a time.

The magic number of processes will be the one that
finishes the whole job quicker. If it is one -as you predict-
so be it. Maybe it's two or three.

-Ramon
How about start with 6 then 3 then 4 or 2 then 5 or 3 or 1.
(the binary thing)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top