Thread question

Hi,

from my thread i call an external perl program like this:

String [] cmdStr = {"perl", Constants.workingPath+ File.separatorChar +"scripts"+File.separatorChar+"get_document.pl", urlPath, database, busquedaFile, Constants.patentesPath};

int exitCode =-1;

Process p=Runtime.getRuntime().exec(cmdStr);

InputStream is = p.getInputStream();

BufferedReader br = new BufferedReader (new InputStreamReader (is));

String cad=br.readLine();

while(br.readLine()!=null)

{

cad=br.readLine();

logger.info(cad);

}

The strange thing is that my thread is blocked EXACTLY IN while(br.readLine()!=null), i.e., it doesnt show the logger.info(cad) which is inside the while...

Any idea?

However he status of the thread is RUNNABLE

T

[818 byte] By [tlloretia] at [2007-11-27 7:43:43]
# 1
That's because reaLine doesn't have any input to return to you yet. It is indeed blocked, but the BLOCKED ThreadState is only used when performing timed wait operations.
Dalzhima at 2007-7-12 19:24:26 > top of Java-index,Core,Core APIs...
# 2
And how could I solve it?
tlloretia at 2007-7-12 19:24:26 > top of Java-index,Core,Core APIs...
# 3
What should be fixed? How do you expect it to behave?Did you even notice you're reading only half of the lines using your loop?
Dalzhima at 2007-7-12 19:24:26 > top of Java-index,Core,Core APIs...
# 4

I've put this while because i've read in a forum that the print of the external programs (similar to System.outof ) should be written somehow to avoid blocking the thread , so that's why i put this while which doesn't do anything useful for my program

while(br.readLine()!=null)

{

cad=br.readLine();

logger.info(cad);

}

is this needed or it only can cause troubles like this?

Thanks!

tlloretia at 2007-7-12 19:24:26 > top of Java-index,Core,Core APIs...
# 5
The problem is that inside your while, you read a line, make sure a line was successfully read, and then inside your loop, instead of using that line you just read, you read a new one and you don't check it! And you don't use it anyway...
Dalzhima at 2007-7-12 19:24:26 > top of Java-index,Core,Core APIs...