Java百战程序员

IO类

1.commons.io.:(工具类包括FileUtils、IOUtils、FilenameUtils和FileSystemUtils,前三者的方法并没有多大的区别,只是操作的对象不同,故名思议:FileUtils主要操作File类,IOUtils主要操作IO流,FilenameUtils则是操作文件名,FileSystemUtils包含了一些JDK没有提供的用于访问文件系统的实用方法。当前,只有一个用于读取硬盘空余空间的方法可用。)
https://blog.csdn.net/wangyanming123/article/details/80217747

多线程

1.注意:多线程在程序中有三种实现方法:继承thread,实现runnable,使用callable。
但我们在使用过程中应该少用继承thread(有局限性),多用实现runnable。但是在使用runnable时也需要调用创建一个Thread对象,并调用他的start()方法来实现现成的启动,因为只有Thread类拥有与cpu互动的权利。
https://blog.csdn.net/maibaodexiaoerlang/article/details/79574842 (good)
https://blog.csdn.net/u012294820/article/details/78721543?locationNum=2&fps=1 (best)
eg.

public class Mytest extends Thread{
	public void run() {
		for(int i=0;i<5;i++) {
			System.out.print(i);
		}
	}
	
	public static void main(String[] args) {
		Mytest st=new Mytest();
		st.start();
		for(int i=0;i<6;i++) {
			System.out.println(i+1);
		}
	}
}

result:

1
2
3
4
5
6
01234

here you can see how the thread run:first ,into main(),then new a object “Mytest”,then start the Mytest thread ,here the cpu will not wait thread"Mytest" finished ,the cpu will continue go on ,it will also go to method below statement “such for()”,and it will also go on the other thread “Mytest”'s “for()” ,like the picture:
在这里插入图片描述

notice :you can not use “st.run()” to start the "Mytest "thread ,because if you use “st.run()” here "run()“will act like a usual method ,so the system will first finish “run()” method, then it finished the “for(…println(,…))”.
when you use"st.start()” we not not ensure when the “Mytest” thread will run ,because the call for thread is all due to the “CPU”.
在这里插入图片描述
https://www.cnblogs.com/yjd_hycf_space/p/7526608.html (best)
说明:
Thread2类通过实现Runnable接口,使得该类有了多线程类的特征。run()方法是多线程程序的一个约定。所有的多线程代码都在run方法里面。Thread类实际上也是实现了Runnable接口的类。
在启动的多线程的时候,需要先通过Thread类的构造方法Thread(Runnable target) 构造出对象,然后调用Thread对象的start()方法来运行多线程代码。
实际上所有的多线程代码都是通过运行Thread的start()方法来运行的。因此,不管是扩展Thread类还是实现Runnable接口来实现多线程,最终还是通过Thread的对象的API来控制线程的,熟悉Thread类的API是进行多线程编程的基础

sleep()和yield()的区别
        sleep()和yield()的区别):sleep()使当前线程进入停滞状态,所以执行sleep()的线程在指定的时间内肯定不会被执行;yield()只是使当前线程重新回到可执行状态,所以执行yield()的线程有可能在进入到可执行状态后马上又被执行。
        sleep 方法使当前运行中的线程睡眼一段时间,进入不可运行状态,这段时间的长短是由程序设定的,yield 方法使当前线程让出 CPU 占有权,但让出的时间是不可设定的。实际上,yield()方法对应了如下操作:先检测当前是否有相同优先级的线程处于同可运行状态,如有,则把 CPU  的占有权交给此线程,否则,继续运行原来的线程。所以yield()方法称为“退让”,它把运行机会让给了同等优先级的其他线程
       另外,sleep 方法允许较低优先级的线程获得运行机会,但 yield()  方法执行时,当前线程仍处在可运行状态,所以,不可能让出较低优先级的线程些时获得 CPU 占有权。在一个运行系统中,如果较高优先级的线程没有调用 sleep 方法,又没有受到 I\O 阻塞,那么,较低优先级线程只能等待所有较高优先级的线程运行结束,才有机会运行。 

volatile:

http://www.cnblogs.com/dolphin0520/p/3920373.html (best)
https://www.cnblogs.com/dolphin0520/ (best)

有状态bean和无状态bean是在说什么

https://blog.csdn.net/bingjing12345/article/details/9794945 (best)

https://blog.csdn.net/u012294820/article/details/78721543?locationNum=2&fps=1 (very good )

可重入锁与不可重入锁

https://blog.csdn.net/u012545728/article/details/80843595 (best)
可重用锁可以和synchronized锁一样可以再次进入的原因是:他们都只有在是同一个当前线程希望在在某个其他方法或属性或对象上在获得锁时才可以重复加锁。而用synchronized可看作一种形式的可重用锁是因为默认那个对象(或类中包含synchronized方法)加了synchronized那个对象就是当前有锁的线程。
https://blog.csdn.net/yanyan19880509/article/details/52345422/ (best)

自旋锁:

https://www.cnblogs.com/charlesblc/p/5994162.html (best)

聊聊cpu内存一致性:

https://blog.csdn.net/yanyan19880509/article/details/52319558 (very best)

网络知识汇总:

https://blog.csdn.net/yanyan19880509/article/details/80788918 (very very best)

猜你喜欢

转载自blog.csdn.net/qq_40590753/article/details/83043514