java.io.BufferedInputStream 在旧的和奇异的 JVM 上的默认缓冲区大小是多少?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2095269/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are the default buffer size for java.io.BufferedInputStream on old and exotic JVMs?
提问by Stu Thompson
I've been doing some research for a blog post regarding java.io.BufferedInputStreamand buffers. Apparently, over the years, the default has grown from a measly 512 bytes to 8192 bytes as of (presumptuously)Sun's Java 7 implementation, and was even explicitly specified in the JavaDocs in JDK 1.1.8. My question has also brought up questions of who/what deciedes what the default should be--it's not as black-n-white as I had expected.
我一直在为一篇关于java.io.BufferedInputStream缓冲区的博客文章做一些研究。显然,多年来,默认值已从(推测)Sun 的 Java 7 实现中的512 字节增加到 8192 字节,甚至在 JDK 1.1.8的JavaDocs 中也有明确指定。我的问题还提出了以下问题:谁/什么决定了默认值应该是什么——它不像我预期的那样黑白分明。
I am curious as to what the default buffer size has been at each version release, and what it may be in other, exotic JVMs. So far I've tracked it down, via source code, JavaDocs or Sun bug reports for 1.0, 1.1, 1.4, Java 5, Java 6 and (presumptuously again)Sun's Java 7 JVM.
我很好奇每个版本的默认缓冲区大小是多少,以及它在其他奇特的 JVM 中可能是什么。到目前为止,我已经通过源代码、JavaDocs 或 Sun 错误报告对 1.0、1.1、1.4、Java 5、Java 6 和(再次假设)Sun 的 Java 7 JVM进行了追踪。
What I've failed to turn up is this value for
我没有找到的是这个值
- Sun JDK 1.2's JVM implementation
- Sun JDK 1.3's implementation
- Any other implementation's value (like IBM or something else)
- Sun JDK 1.2 的 JVM 实现
- Sun JDK 1.3 的实现
- 任何其他实现的价值(如 IBM 或其他东西)
So, I was wondering what those values are and where I could find a reference to them?
所以,我想知道这些值是什么以及在哪里可以找到对它们的引用?
Or, that baring, if any SOpedians out there might have access to one of these installations. If so, could you compile and run the below code, and then report back here? Or, do you know of
或者,如果那里的任何 SOpedians 可能可以访问这些安装之一,那就太棒了。如果是这样,您能否编译并运行以下代码,然后在此处报告?或者,你知道吗
import java.io.BufferedInputStream;
import java.io.InputStream;
public class BufferSizeDetector extends BufferedInputStream {
public static void main(String[] args) {
BufferSizeDetector bsd = new BufferSizeDetector(null);
System.err.println(System.getProperty("java.version"));
System.err.println(bsd.getBufferSize());
}
public BufferSizeDetector(InputStream in) {
super(in);
}
public int getBufferSize() {
return super.buf.length;
}
}
回答by Jean-Philippe Pellet
Mac OS X Tiger 10.7.0, default Apple-provided VM:
Mac OS X Tiger 10.7.0,Apple 提供的默认 VM:
Java(TM) SE Runtime Environment (build 1.6.0_26-b03-383-11A511)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-383, mixed mode)
Then:
然后:
1.6.0_26
8192
回答by Max A.
The system:
系统:
Linux wart 2.6.33-rc1-00225-gc9f937e #2 Wed Dec 23 17:55:01 UTC 2009 armv5tel GNU/Linux
OpenJDK Runtime Environment (IcedTea6 1.4.1) (6b14-1.4.1-0ubuntu10)
OpenJDK Core VM (build 14.0-b08, interpreted mode)
The output from your program:
程序的输出:
1.6.0_0
8192
回答by kevinarpe
Run from my IntelliJ in Windows 7:
在 Windows 7 中从我的 IntelliJ 运行:
- JRE: 1.8.0_112-release-724-b6 amd64
- JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
- Windows 7 6.1
- JRE:1.8.0_112-release-724-b6 amd64
- JVM:JetBrains sro 的 OpenJDK 64 位服务器 VM
- 视窗 7 6.1
Output:
输出:
1.8.0_121
8192
回答by McDowell
I'm not sure what you hope to learn from this, but since I have it in front of me... a win32 IBM 1.4.2 JRE uses a buffer size of 2048.
我不确定您希望从中学到什么,但既然我已经有了它……一个 win32 IBM 1.4.2 JRE 使用的缓冲区大小为2048.

