![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Java Demo
文章平均质量分 65
arccosY
www.github.com/arcsinY
展开
-
Java有缓冲与无缓冲读写效率对比
将1~100000整数写入(读取)out.txt文件中,记录不同写入方式的运行时间 一、无缓冲写 public class Main { public static void main(String[] args) throws Exception { FileOutputStream fos = new FileOutputStream("D:\\out.txt"); long start = System.currentTimeMillis();原创 2021-08-18 19:28:05 · 340 阅读 · 1 评论 -
Java多线程修改数据
问题定义: 定义一个类Number,其中包括变量num。多个线程对num进行读取和减1的操作。 一、不安全的实现 将num定义成静态变量: public class Number { public static int num = 30; public static AtomicInteger cnt = new AtomicInteger(0); } 为了更好地看出线程多num的操作是否正确,用cnt来记录对num修改的次数,每有一个线程对num减去了1,就将cnt+1。cnt是Atom原创 2021-01-24 21:19:13 · 2500 阅读 · 0 评论