How does InputStreamReader.close () work?

It seems that the actual implementation of close() hidden somewhere in the hierarchy of base classes and implementations of abstract methods. For example, are you guaranteed to release a file descriptor? Here is the closest to what I wanted to know:

  nd.preClose(fd); long th; if ((th = readerThread) != 0) NativeThread.signal(th); if ((th = writerThread) != 0) NativeThread.signal(th); if (!isRegistered()) kill(); 

from DatagramChannelImpl . Can anyone translate into English?

+6
source share
2 answers

So, every time I start to immerse Sun's <strike> Oracle Java code, I am disappointed. nd how is the variable name? Doesn't become more opaque than that.

That nd refers to NativeDispatcher , which handles specific platform operations, such as closing file descriptors (kindly called the fd variable). I can only assume that the NativeThread check and the signal clear the read / write streams, the source does not provide much information. isRegistered() from AbstractSelectableChannel ensures that the channel is not used, and the kill method is what closes everything and finally calls nd.close (FD);

+4
source

From Javadoc: "Closes a thread and frees up associated system resources." The FD file is a system resource. Ergo is closing.

0
source

Source: https://habr.com/ru/post/910868/


All Articles