Skip to main content

100 threads using Runtime in Eclipse

2 replies [Last post]
paweladamczak
Offline
Joined: 2009-01-11
Points: 0

Hello,
My purpose is to run 100 threads, which will be running php programs.
As long as these programs php are identicall there is no problem.
The problem is when there are 100 different programs. - Threads are still alive and never finish. The code looks like:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class MyRunnableClass implements Runnable
{
public MyRunnableClass (String program)
{
inputToPhp[0]="php";
inputToPhp[1]="-r";
inputToPhp[2]=program;
}

public void run()
{

try
{ r = Runtime.getRuntime();
p = r.exec(inputToPhp);
}
catch( IOException f)
{
System.err.println("IOException!");
p.destroy();
}

try
{p.waitFor();}
catch( InterruptedException e )
{p.destroy();}

reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
//...
//...
//...
}

private BufferedReader reader;
private String[] inputToPhp = new String[3];
private Runtime r;
private Process p;
}

public class Population
{
public static void main(String args[])
{

int POPULATION=100;
int delay = 1000;
int nMills= 10000;
int nTimes = nMills/delay;

String[] programs= {}; //...
//contains 100 different simple programs without errors
// for example "echo('something');"

MyRunnableClass[] r = new MyRunnableClass[POPULATION];
Thread[] php = new Thread[POPULATION];

// here I'm starting all threads
for (int i=0;i

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
paweladamczak
Offline
Joined: 2009-01-11
Points: 0

Sorry, I have problem with text.

peter__lawrey
Offline
Joined: 2005-11-01
Points: 0

When you use a debugger what does it say the threads are doing?