简体   繁体   English

InputStreamReader.close() 在内部如何工作?

[英]How does InputStreamReader.close() work internally?

It seems that the actual close() implementation is tucked away somewhere in the hierarchy of base classes and implementations of abstract methods.似乎实际的close()实现隐藏在基类层次结构和抽象方法实现的某个地方。 For example, are you guaranteed that the file descriptor gets released?例如,你能保证文件描述符被释放吗? Here is the closest thing 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 .来自DatagramChannelImpl Can anyone translate into English?谁能翻译成英文?

So every time I source dive Sun Oracle's Java code I am disappointed.因此,每次我深入研究 Sun Oracle 的 Java 代码时,我都会感到失望。 nd as a variable name? nd作为变量名? Does not get more opaque than that.没有比这更不透明的了。

What nd is referencing is NativeDispatcher which handles platform specific operations, such as closing File Descriptors (kindly named the variable fd ). nd引用的是NativeDispatcher ,它处理平台特定的操作,例如关闭文件描述符(亲切地命名为变量fd )。 I can only assume the NativeThread check and signal is to clean up the read/write threads, the source does not lend much information.我只能假设NativeThread检查和信号是清理读/写线程,来源没有提供太多信息。 The isRegistered() from AbstractSelectableChannel makes sure the Channel is not being used and the kill method is what closes everything down and finally calls the nd.close(fd); AbstractSelectableChannelisRegistered()确保 Channel 没有被使用, kill方法是关闭一切并最终调用nd.close(fd);

From the Javadoc: "Closes the stream and releases any system resources associated with it".来自 Javadoc:“关闭流并释放与之关联的任何系统资源”。 The file FD is a system resource.文件FD是系统资源。 Ergo it gets closed.因此它会关闭。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM