File tree Expand file tree Collapse file tree 5 files changed +72
-4
lines changed Expand file tree Collapse file tree 5 files changed +72
-4
lines changed Original file line number Diff line number Diff line change @@ -51,10 +51,11 @@ new、静态字段或方法被使用、反射、父类、main函数调用
5151扩展类加载器:它负责加载<JAVA_HOME>/lib/ext目录下或者由系统变量-Djava.ext.dir指定位路径中的类库,开发者可以直接使用标准扩展类加载器
5252系统类加载器:它负责加载系统类路径java -classpath或-D java.class.path 指定路径下的类库
5353
54- 如果父类加载器可以完成类加载任务,就成功返回,倘若父类加载器无法完成此加载任务,子加载器才会尝试自己去加载,这就是** 双亲委派模式** 。
54+ 定义: 如果父类加载器可以完成类加载任务,就成功返回,倘若父类加载器无法完成此加载任务,子加载器才会尝试自己去加载,这就是** 双亲委派模式** 。
5555
56- 采用双亲委派模式的是好处是Java类随着它的类加载器一起具备了一种带有优先级的层次关系,通过这种层级关可以避免类的重复加载,当父亲已经加载了该类时,就没有必要子ClassLoader再加载一次。其次防止恶意覆盖Java核心API。
56+ 优点: 采用双亲委派模式的是好处是Java类随着它的类加载器一起具备了一种带有优先级的层次关系,通过这种层级关可以避免类的重复加载,当父亲已经加载了该类时,就没有必要子ClassLoader再加载一次。其次防止恶意覆盖Java核心API。
5757
58+ 破坏双亲委派模式:是为了实现自己的类加载逻辑,达到比如[ 热部署重加载] ( https://blog.csdn.net/u010833547/article/details/54312052 ) 的功能,默认加载器在加载类的时候会检测该类是否已经存在,如果存在则不会去加载,如果不存在则加载该类并缓存。所以默认的ClassLoader是无法实现热替换的。换句话说,要实现热替换就必须实现一个自己的MyClassLoader。双亲委派的逻辑是写在ClassLoader中的loadClass中的,所以继承ClassLoader然后覆盖loadClass方法,读取自己允许热加载的那些类吧~
5859
5960### 内存分配(堆上的内存分配)
6061![ ] ( https://github.com/xbox1994/2018-Java-Interview/raw/master/images/j2.jpg )
@@ -93,5 +94,17 @@ GC Roots包括:虚拟机栈中引用的对象、方法区中类静态属性引
93942 . 老年代空间不足(通过Minor GC后进入老年代的大小大于老年代的可用内存)
94953 . 方法区空间不足
9596
97+ ## Java内存模型
98+ 主内存:所有变量都保存在主内存中
99+ 工作内存:每个线程的独立内存,保存了该线程使用到的变量的主内存副本拷贝,线程对变量的操作必须在工作内存中进行
100+
101+ ![ ] ( https://github.com/xbox1994/2018-Java-Interview/raw/master/images/j12.png )
102+
103+ 每个线程都有自己的本地内存共享副本,如果A线程要更新主内存还要让B线程获取更新后的变量,那么需要:
104+
105+ 1 . 将本地内存A中更新共享变量
106+ 2 . 将更新的共享变量刷新到主内存中
107+ 3 . 线程B从主内存更新最新的共享变量
108+
96109## JVM调优
97110[ https://www.ibm.com/developerworks/cn/java/j-lo-jvm-optimize-experience/index.html ] ( https://www.ibm.com/developerworks/cn/java/j-lo-jvm-optimize-experience/index.html )
Original file line number Diff line number Diff line change 663 . 实现:在Java里如何实现线程,Thread、Runnable、Callable。
774 . 问题:线程可以获得更大的吞吐量,但是开销很大,线程栈空间的大小、切换线程需要的时间,所以用到线程池进行重复利用,当线程使用完毕之后就放回线程池,避免创建与销毁的开销。
88
9- ### 如何实现同步
10- [ https://fangjian0423.github.io/2016/04/18/java-synchronize-way/ ] ( https://fangjian0423.github.io/2016/04/18/java-synchronize-way/ )
9+ ### 线程同步/线程间通信的方式
10+ https://fangjian0423.github.io/2016/04/18/java-synchronize-way/
11+ https://github.com/crossoverJie/Java-Interview/blob/master/MD/concurrent/thread-communication.md
1112
1213### 锁
1314#### 锁是什么
Original file line number Diff line number Diff line change @@ -193,4 +193,54 @@ public class QuickSort {
193193 }
194194
195195}
196+ ```
197+
198+ ### 交替打印奇偶数
199+ ``` java
200+ public class PrintOddAndEvenShu {
201+ private int value = 0 ;
202+
203+ private synchronized void printOdd () {
204+ while (value <= 100 ) {
205+ if (value % 2 == 1 ) {
206+ System . out. println(Thread . currentThread() + " : -" + value++ );
207+ this . notify();
208+ } else {
209+ try {
210+ this . wait();
211+ } catch (InterruptedException e) {
212+ e. printStackTrace();
213+ }
214+ }
215+
216+ }
217+
218+ }
219+
220+ private synchronized void printEven () {
221+ while (value <= 100 ) {
222+ if (value % 2 == 0 ) {
223+ System . out. println(Thread . currentThread() + " : --" + value++ );
224+ this . notify();
225+ } else {
226+ try {
227+ this . wait();
228+ } catch (InterruptedException e) {
229+ e. printStackTrace();
230+ }
231+ }
232+ }
233+ }
234+
235+ public static void main (String [] args ) throws InterruptedException {
236+ PrintOddAndEvenShu print = new PrintOddAndEvenShu ();
237+ Thread t1 = new Thread (print:: printOdd);
238+ Thread t2 = new Thread (print:: printEven);
239+ t1. start();
240+ t2. start();
241+ t1. join();
242+ t2. join();
243+ }
244+ }
245+
196246```
Original file line number Diff line number Diff line change @@ -29,10 +29,14 @@ PS:除开知识点,一定要准备好以下内容:
2929* [ 事务] ( https://mp.weixin.qq.com/s/RDnf637MY0IVgv2NpNVByw )
3030* [ 消息队列] ( https://github.com/xbox1994/2018-Java-Interview/blob/master/MD/分布式-消息队列.md )
3131* [ 存储] ( https://blog.csdn.net/prettyeva/article/details/60146668 )
32+ * [ 限流] ( https://crossoverjie.top/2018/04/28/sbc/sbc7-Distributed-Limit )
33+ * [ ID生成方式] ( https://github.com/crossoverJie/Java-Interview/blob/master/MD/ID-generator.md )
34+ * [ 高并发场景解决思路] ( http://www.wangtianyi.top/blog/2018/05/11/javaduo-xian-cheng-yu-gao-bing-fa-liu-gao-bing-fa-jie-jue-si-lu/ )
3235### [ 在线编程] ( https://github.com/xbox1994/2018-Java-Interview/blob/master/MD/在线编程.md )
3336### [ Linux] ( https://github.com/xbox1994/2018-Java-Interview/blob/master/MD/Linux.md )
3437----------------
3538### [ 搜索引擎] ( https://github.com/xbox1994/2018-Java-Interview/blob/master/MD/搜索引擎.md )
3639搜索引擎是因为个人项目关系,那个搜索引擎非常简单,但有很多东西可以问到,可选择性学习借鉴,了解到对项目是如何提问的,还有问题的深度
3740### [ 秒杀架构] ( https://github.com/xbox1994/2018-Java-Interview/blob/master/MD/秒杀架构.md )
3841### [ 问题排查] ( https://github.com/xbox1994/2018-Java-Interview/blob/master/MD/问题排查.md )
42+ ### [ 从按下回车开始,到浏览器呈现出网页之间的发生了什么] ( http://www.wangtianyi.top/blog/2017/10/22/cong-urlkai-shi-,ding-wei-shi-jie/ )
You can’t perform that action at this time.
0 commit comments