您现在的位置是:主页 > news > wordpress标签查看id/qq群排名优化软件

wordpress标签查看id/qq群排名优化软件

admin2025/5/10 20:12:55news

简介wordpress标签查看id,qq群排名优化软件,网页设计师学习网站,常州市网站制作缓冲 缓冲可以理解为漏斗一样,是为了解决上下层的性能差异而出现的,缓冲可以有效的减少上层组件对下层组件的等待时间 在JDK中,IO使用缓冲是最多的 主要就这四类,那么建议以后所有IO操作都是用这四个类来操作 import java.io.*;…

wordpress标签查看id,qq群排名优化软件,网页设计师学习网站,常州市网站制作缓冲 缓冲可以理解为漏斗一样,是为了解决上下层的性能差异而出现的,缓冲可以有效的减少上层组件对下层组件的等待时间 在JDK中,IO使用缓冲是最多的 主要就这四类,那么建议以后所有IO操作都是用这四个类来操作 import java.io.*;…

缓冲

缓冲可以理解为漏斗一样,是为了解决上下层的性能差异而出现的,缓冲可以有效的减少上层组件对下层组件的等待时间

在JDK中,IO使用缓冲是最多的


主要就这四类,那么建议以后所有IO操作都是用这四个类来操作

import java.io.*;public class Demo {static int len = 100000;static String content = "Hello World !\n";static String path = new File("").getAbsolutePath()+File.separator+"demo.txt";public static void main(String[] args) {Writer writer = null;try {writer = new BufferedWriter(new FileWriter(new File(path)));//默认构造8K的缓冲区} catch (IOException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}long begin = System.currentTimeMillis();try {for(int i=0;i<len;i++) {writer.write(content);}writer.close();} catch (IOException e) {e.printStackTrace();}long end = System.currentTimeMillis();System.out.println(end-begin);//-----------------------------------try {writer =new FileWriter(new File(path));} catch (IOException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}begin = System.currentTimeMillis();try {for(int i=0;i<len;i++) {writer.write(content);}writer.close();} catch (IOException e) {e.printStackTrace();}end = System.currentTimeMillis();System.out.println(end-begin);}
}
27
60
从结果中可以看出来差异了,有明显的性能差异


import java.io.*;public class Demo {static int len = 100000;static String content = "Hello World !\n";static String path = new File("").getAbsolutePath()+File.separator+"demo.txt";public static void main(String[] args) {Reader reader = null;try {reader = new BufferedReader(new FileReader(new File(path)));} catch (IOException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}long begin = System.currentTimeMillis();try {for(int i=0;i<len;i++) {reader.read();}reader.close();} catch (IOException e) {e.printStackTrace();}long end = System.currentTimeMillis();System.out.println(end-begin);//-----------------------------------try {reader =new FileReader(new File(path));} catch (IOException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}begin = System.currentTimeMillis();try {for(int i=0;i<len;i++) {reader.read();}reader.close();} catch (IOException e) {e.printStackTrace();}end = System.currentTimeMillis();System.out.println(end-begin);}
}
9
40
读取差异

import java.io.*;public class Demo {static int len = 100000;static String content = "Hello World !\n";static String path = new File("").getAbsolutePath()+File.separator+"demo.txt";public static void main(String[] args) {InputStream reader = null;try {reader = new BufferedInputStream(new FileInputStream(new File(path)));} catch (IOException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}long begin = System.currentTimeMillis();try {for(int i=0;i<len;i++) {reader.read();}reader.close();} catch (IOException e) {e.printStackTrace();}long end = System.currentTimeMillis();System.out.println(end-begin);//-----------------------------------try {reader = new FileInputStream(new File(path));} catch (IOException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}begin = System.currentTimeMillis();try {for(int i=0;i<len;i++) {reader.read();}reader.close();} catch (IOException e) {e.printStackTrace();}end = System.currentTimeMillis();System.out.println(end-begin);}
}
8
172
差异很明显
import java.io.*;public class Demo {static int len = 100000;static String content = "Hello World !\n";static String path = new File("").getAbsolutePath()+File.separator+"demo.txt";public static void main(String[] args) {OutputStream writer = null;try {writer = new BufferedOutputStream(new FileOutputStream(new File(path)));} catch (IOException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}long begin = System.currentTimeMillis();try {for(int i=0;i<len;i++) {writer.write(content.getBytes());}writer.close();} catch (IOException e) {e.printStackTrace();}long end = System.currentTimeMillis();System.out.println(end-begin);//-----------------------------------try {writer = new FileOutputStream(new File(path));} catch (IOException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}begin = System.currentTimeMillis();try {for(int i=0;i<len;i++) {writer.write(content.getBytes());}writer.close();} catch (IOException e) {e.printStackTrace();}end = System.currentTimeMillis();System.out.println(end-begin);}
}
50
392
从以上四种缓冲类来看,明显比非缓冲类效果更佳

建议JAVA IO操作全部采用缓冲类来实现

缓存

缓存就是存储用户最近最频繁访问的数据,免得用户每次都从主存中读取数据

JAVA中最为简单的缓存就是HashMap实现

数据库连接池