BufferedReader.readLine() hangs

dave.held_at_arrayservicesgrp.com
Date: 01/31/05


Date: 31 Jan 2005 14:46:52 -0800

The following program hangs on Linux 2.4.20, jre 1.5.0-01-b08,
server VM with a suitably large input file (say, 4+ MB):

import java.io.BufferedReader;
import java.io.FileReader;

public class ReadTest
{
public static void main(String[] args)
{
try
{
BufferedReader in = new BufferedReader(new
FileReader(args[0]));
in.readLine();
do
{
ReadTest.getRow(in);
}
while (in.ready());
}
catch (Exception e)
{
e.printStackTrace();
}
}

public static void getRow(BufferedReader in) throws Exception
{
int n = 0;
while (in.ready())
{
System.out.println(in.readLine());
if (++n > 10) return;
}
}
}

It does not hang in the client VM. It does not hang if the readLine()
call occurs in the outermost loop. It does not hang consistently. It
does not always hang. But when it does hang, it appears to do so
indefinitely. When it hangs, I can suspend the process, and when I
resume it, the process continues normally to completion. Any idea
what is going on?

Dave