Kevin Zhou wrote:
> I think Regis's suggestion, to shrink the synchronized block only on buff
> object, is good, as for one aspect of performance improvement.
> But we already confirmed that RI synchronizes its BufferedInputStream.read()
> method.
> We have to follows the behaviors in the short terms to be compatible with
> RI.
I don't think it will help (or I don't understand your suggestion).
The goal is to allow the close() to occur asynchronously to a read(),
while maintaining the coherency of the buffered input stream.
This is most likely to be an issue when you have underlying sockets,
where the read will block but you can still close it.
The example below will work on the RI, but block indefinitely on Harmony:
ServerSocket server = new ServerSocket(0);
Socket client = new Socket(InetAddress.getLocalHost(),
server.getLocalPort());
final BufferedInputStream bis = new
BufferedInputStream(client.getInputStream());
Thread reader = new Thread(new Runnable() {
public void run() {
System.out.println("Reading...");
try {
bis.read();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
// Wait for the read to block
reader.start();
System.out.println("Waiting...");
Thread.sleep(1000); // Urgh
System.out.println("Closing...");
bis.close();
client.close();
server.close();