H
Henning Moll
Hi!
This is not the usual 'why gets my thread blocked' problem. So please
read on... ;-)
In fact, it's the other way round: The thread is not blocked.
A short example:
---snip---
import java.io.*;
public class TTT
{
public static void main(String[] args) throws IOException
{
PipedInputStream pis = new PipedInputStream();
final PrintStream pipe_start = new PrintStream(
new PipedOutputStream(pis));
Thread t = new Thread() {
public void run()
{
for(int i = 0 ; i < 100000 ; i++ )
{
pipe_start.println(i);
System.out.println(i); //Just to have some feedback
}
pipe_start.close();
System.out.println("thread finished...");
}
};
t.start();
/*This is the problem: Only one byte gets read, but
*the thread t gets never blocked. Why?
*If you comment out the following line, thread t
*gets blocked after some loops
*/
pis.read();
System.out.println("main finished");
}
}
---snip---
I allready figured out a part of the problem: Thread t is not blocked
because the main thread is finish. If you put something like
while(t.isAlive()) { }
just before 'main finished', thread t gets blocked again.
Now, how can thread t write to the pipe while the other 'end' of the
pipe is not alive anymore? There is no exception thrown (broken pipe
or similar)
And apart of that: The pipe-buffer should also be filled up to the
limit. Why is thread t not blocked?
confused
Henning
This is not the usual 'why gets my thread blocked' problem. So please
read on... ;-)
In fact, it's the other way round: The thread is not blocked.
A short example:
---snip---
import java.io.*;
public class TTT
{
public static void main(String[] args) throws IOException
{
PipedInputStream pis = new PipedInputStream();
final PrintStream pipe_start = new PrintStream(
new PipedOutputStream(pis));
Thread t = new Thread() {
public void run()
{
for(int i = 0 ; i < 100000 ; i++ )
{
pipe_start.println(i);
System.out.println(i); //Just to have some feedback
}
pipe_start.close();
System.out.println("thread finished...");
}
};
t.start();
/*This is the problem: Only one byte gets read, but
*the thread t gets never blocked. Why?
*If you comment out the following line, thread t
*gets blocked after some loops
*/
pis.read();
System.out.println("main finished");
}
}
---snip---
I allready figured out a part of the problem: Thread t is not blocked
because the main thread is finish. If you put something like
while(t.isAlive()) { }
just before 'main finished', thread t gets blocked again.
Now, how can thread t write to the pipe while the other 'end' of the
pipe is not alive anymore? There is no exception thrown (broken pipe
or similar)
And apart of that: The pipe-buffer should also be filled up to the
limit. Why is thread t not blocked?
confused
Henning