2021面试题准备~~~
- Jvm的内存结构,jvm调优,如何dump堆排查问题,内存泄露
内存结构: jvm内存分为堆(线程共享,线程不安全) 和栈(线程独享,线程安全),
内存区域:
A:线程私有区域:虚拟机栈,本地方法栈,计数器(指向虚拟机字节码位置,唯一一个无oom)
B:线程共享区域:虚拟机Java堆(新生代eden,s1,s2 + 老年代 + 堆满了会出现OOM),方法区(永久代,存储运行时常量池,Runtime contant pool)
C:直接分配区域:不受JVM 的GC管理, 可以使用 Native 函数库直接分配堆外内存,在特定情况避免的了java堆和native堆之间复制数据,显著提高性能.
如何dump堆排查问题:
Java如何生成Heap Dump及OOM问题排查

Heap Dump简述
Heap dump
文件是一个二进制文件,它保存了某一时刻JVM堆中对象使用情况。Heap Dump
文件是指定时刻的Java堆栈的快照,是一种镜像文件。Heap Dump
一般都包含了一个堆中的Java Objects, Class等基本信息。同时,当你在执行一个转储操作时,往往会触发一次GC,所以你转储得到的文件里包含的信息通常是有效的内容(包含比较少,或没有垃圾对象了) 。我们可以这么理解:heap dump记录内存信息的,thread dump是记录CPU信息的。
Heap Dump 包含的信息
- 所有的对象信息
对象的类信息、字段信息、原生值(int, long等)及引用值 - 所有的类信息
类加载器、类名、超类及静态字段 - 垃圾回收的根对象
根对象是指那些可以直接被虚拟机触及的对象 - 线程栈及局部变量
包含了转储时刻的线程调用栈信息和栈帧中的局部变量信息
Heap Dump 获取方式
1. 使用 jmap 命令生成 dump 文件
jmap -dump:live,format=b,file=c:\dump\heap.hprof <pid>
eg. 1) 在windows主机上面通过tasklist
获取进程pid
C:\Program Files (x86)\PowerCmd>tasklist
映像名称 PID 会话名 会话# 内存使用
========================= ======== ================ =========== ============
System Idle Process 0 Services 0 8 K
System 4 Services 0 1,256 K
Registry 96 Services 0 22,608 K
smss.exe 448 Services 0 1,028 K
csrss.exe 656 Services 0 4,532 K
wininit.exe 760 Services 0 5,764 K
csrss.exe 768 Console 1 5,088 K
services.exe 832 Services 0 9,912 K
lsass.exe 840 Services 0 16,356 K
svchost.exe 960 Services 0 3,816 K
svchost.exe 984 Services 0 26,528 K
fontdrvhost.exe 68 Services 0 3,116 K
svchost.exe 524 Services 0 13,408 K
svchost.exe 904 Services 0 7,524 K
winlogon.exe 1104 Console 1 8,312 K
fontdrvhost.exe 1160 Console 1 21,644 K
dwm.exe 1244 Console 1 84,076 K
aesm_service.exe 1308 Services 0 6,568 K
svchost.exe 1372 Services 0 9,288 K
svchost.exe 1380 Services 0 11,288 K
svchost.exe 1444 Services 0 13,780 K
svchost.exe 1504 Services 0 5,780 K
svchost.exe 1548 Services 0 10,036 K
svchost.exe 1632 Services 0 9,492 K
svchost.exe 1716 Services 0 14,568 K
svchost.exe 1760 Services 0 8,804 K
svchost.exe 1768 Services 0 14,340 K
ibmpmsvc.exe 1852 Services 0 4,920 K
LPlatSvc.exe 1864 Services 0 6,768 K
NVDisplay.Container.exe 2036 Services 0 9,180 K
svchost.exe 1020 Services 0 8,372 K
AliSystemSrv.exe 1736 Services 0 5,536 K
svchost.exe 2084 Services 0 7,400 K
NVDisplay.Container.exe 2156 Console 1 17,744 K
svchost.exe 2240 Services 0 11,468 K
svchost.exe 2324 Services 0 9,508 K
svchost.exe 2332 Services 0 12,056 K
svchost.exe 2440 Services 0 12,204 K
svchost.exe 2448 Services 0 5,672 K
svchost.exe 2456 Services 0 7,620 K
svchost.exe 2540 Services 0 7,636 K
Memory Compression 2548 Services 0 20,356 K
igfxCUIService.exe 2600 Services 0 7,368 K
svchost.exe 2660 Services 0 7,440 K
svchost.exe 2668 Services 0 11,972 K
svchost.exe 2800 Services 0 11,972 K
RtkAudioService64.exe 2876 Services 0 6,016 K
svchost.exe 2884 Services 0 17,460 K
svchost.exe 3024 Services 0 6,236 K
svchost.exe 3032 Services 0 8,416 K
svchost.exe 3040 Services 0 11,056 K
svchost.exe 3124 Services 0 12,428 K
audiodg.exe 3196 Services 0 31,912 K
svchost.exe 3292 Services 0 14,592 K
sihost.exe 3332 Console 1 24,480 K
svchost.exe 3356 Console 1 21,252 K
PresentationFontCache.exe 3404 Services 0 23,492 K
svchost.exe 3492 Console 1 32,452 K
svchost.exe 3500 Services 0 11,212 K
spoolsv.exe 3660 Services 0 11,104 K
TpShocks.exe 3668 Console 1 1,308 K
taskhostw.exe 3736 Console 1 16,028 K
wlanext.exe 3820 Services 0 12,700 K
svchost.exe 3828 Services 0 7,920 K
conhost.exe 3852 Services 0 4,832 K
svchost.exe 3984 Services 0 28,616 K
svchost.exe 3992 Services 0 7,400 K
ctfmon.exe 4064 Console 1 24,704 K
explorer.exe 4104 Console 1 145,340 K
WmiPrvSE.exe 4308 Services 0 16,784 K
AlibabaProtect.exe 4420 Services 0 78,640 K
IntelCpHDCPSvc.exe 4428 Services 0 6,636 K
svchost.exe 4436 Services 0 5,888 K
svchost.exe 4444 Services 0 24,352 K
OfficeClickToRun.exe 4464 Services 0 21,692 K
svchost.exe 4472 Services 0 13,008 K
svchost.exe 4484 Services 0 29,204 K
EvtEng.exe 4492 Services 0 11,484 K
FoxitProtect.exe 4500 Services 0 14,080 K
ibtsiva.exe 4540 Services 0 3,964 K
GfExperienceService.exe 4548 Services 0 9,816 K
iNodeMon.exe 4592 Services 0 8,988 K
svchost.exe 4624 Services 0 11,688 K
micmute.exe 4740 Services 0 9,532 K
svchost.exe 4764 Services 0 8,124 K
mysqld.exe 4772 Services 0 23,888 K
NvNetworkService.exe 4788 Services 0 9,484 K
svchost.exe 4796 Services 0 9,896 K
QQProtect.exe 4824 Services 0 14,552 K
pcas.exe 4832 Services 0 13,752 K
RegSrvc.exe 4892 Services 0 8,400 K
SecurityHealthService.exe 4924 Services 0 11,672 K
SynTPEnhService.exe 4976 Services 0 8,300 K
svchost.exe 5032 Services 0 5,404 K
tphkload.exe 5040 Services 0 10,328 K
TeamViewer_Service.exe 5048 Services 0 13,400 K
MsMpEng.exe 5068 Services 0 156,560 K
svchost.exe 5108 Services 0 20,796 K
ZeroConfigService.exe 5140 Services 0 12,708 K
SynTPEnh.exe 5336 Console 1 16,524 K
iNodeImg.exe 5396 Console 1 6,608 K
conhost.exe 5480 Console 1 5,076 K
igfxEM.exe 5880 Console 1 10,736 K
svchost.exe 6008 Services 0 7,368 K
svchost.exe 5192 Services 0 7,012 K
dasHost.exe 5448 Services 0 4,644 K
WmiPrvSE.exe 6304 Services 0 10,932 K
IntelCpHeciSvc.exe 6400 Services 0 9,452 K
svchost.exe 6600 Services 0 5,708 K
iNodeCmn.exe 6908 Console 1 12,768 K
iNodeSec.exe 6916 Console 1 10,240 K
conhost.exe 6948 Console 1 5,084 K
conhost.exe 6964 Console 1 5,096 K
iNodeSslvpn.exe 6980 Console 1 10,536 K
iNodeL2tpIPSecvpn.exe 6996 Console 1 10,184 K
conhost.exe 7020 Console 1 5,084 K
conhost.exe 7036 Console 1 5,080 K
svchost.exe 7048 Services 0 7,812 K
svchost.exe 7296 Services 0 6,956 K
SynTPHelper.exe 7684 Console 1 4,216 K
unsecapp.exe 8124 Services 0 6,508 K
tposd.exe 8404 Console 1 11,380 K
shtctky.exe 8412 Console 1 7,776 K
rundll32.exe 8940 Console 1 4,556 K
svchost.exe 9076 Services 0 15,240 K
ShellExperienceHost.exe 8344 Console 1 71,196 K
SearchUI.exe 9248 Console 1 66,488 K
RuntimeBroker.exe 9424 Console 1 22,232 K
TSVNCache.exe 9476 Console 1 10,896 K
RuntimeBroker.exe 9688 Console 1 27,068 K
NisSrv.exe 9864 Services 0 10,104 K
SettingSyncHost.exe 10180 Console 1 5,600 K
Video.UI.exe 3644 Console 1 16,324 K
svchost.exe 3172 Services 0 9,772 K
SkypeHost.exe 10292 Console 1 32,116 K
LockApp.exe 10368 Console 1 29,224 K
svchost.exe 10428 Services 0 15,640 K
RuntimeBroker.exe 10500 Console 1 27,780 K
SearchIndexer.exe 10748 Services 0 45,120 K
GoogleCrashHandler.exe 10464 Services 0 1,228 K
GoogleCrashHandler64.exe 10100 Services 0 912 K
RuntimeBroker.exe 3628 Console 1 19,016 K
igfxext.exe 8672 Console 1 7,968 K
svchost.exe 10268 Console 1 21,696 K
RuntimeBroker.exe 11552 Console 1 16,036 K
RuntimeBroker.exe 11804 Console 1 7,096 K
MySQLNotifier.exe 11880 Console 1 41,156 K
RuntimeBroker.exe 11976 Console 1 13,180 K
svchost.exe 12016 Services 0 29,620 K
ss_privoxy.exe 5172 Console 1 8,336 K
jusched.exe 11936 Console 1 15,572 K
RAVBg64.exe 9844 Console 1 2,172 K
RAVCpl64.exe 11540 Console 1 3,184 K
svchost.exe 8880 Services 0 7,168 K
ApplicationFrameHost.exe 11284 Console 1 31,024 K
WinStore.App.exe 1672 Console 1 36,976 K
Calculator.exe 11392 Console 1 20,856 K
RuntimeBroker.exe 9004 Console 1 5,840 K
dllhost.exe 9440 Console 1 9,624 K
sppsvc.exe 3616 Services 0 12,000 K
svchost.exe 4116 Services 0 13,868 K
jhi_service.exe 11724 Services 0 6,284 K
LMS.exe 11660 Services 0 10,900 K
SgrmBroker.exe 12100 Services 0 5,040 K
svchost.exe 9528 Services 0 8,528 K
AlibabaprotectUI.exe 4208 Console 1 21,368 K
svchost.exe 5896 Services 0 8,380 K
svchost.exe 9380 Services 0 10,940 K
svchost.exe 6156 Services 0 5,352 K
WeChat.exe 12480 Console 1 71,152 K
WeChatWeb.exe 8952 Console 1 18,216 K
DingTalk.exe 13052 Console 1 121,000 K
DingTalkHelper.exe 12588 Console 1 109,936 K
DingTalk.exe 3952 Console 1 10,964 K
cloudmusic.exe 12372 Console 1 46,304 K
cloudmusic.exe 13348 Console 1 75,912 K
cloudmusic.exe 13464 Console 1 65,080 K
QQ.exe 5772 Console 1 244,204 K
TXPlatform.exe 13780 Console 1 2,952 K
WindowsInternal.Composabl 5164 Console 1 25,592 K
SogouCloud.exe 13812 Console 1 16,908 K
QQExternal.exe 13720 Console 1 52,072 K
svchost.exe 4844 Services 0 7,012 K
svchost.exe 8904 Services 0 9,836 K
FoxitReaderPlus.exe 13580 Console 1 54,888 K
SogouImeBroker.exe 13892 Console 1 20,252 K
chrome.exe 5028 Console 1 166,544 K
chrome.exe 3848 Console 1 7,600 K
chrome.exe 3060 Console 1 7,916 K
chrome.exe 14000 Console 1 62,864 K
chrome.exe 12336 Console 1 60,712 K
chrome.exe 13932 Console 1 30,800 K
chrome.exe 13924 Console 1 29,288 K
idea64.exe 3720 Console 1 760,276 K
fsnotifier64.exe 14712 Console 1 3,976 K
conhost.exe 12672 Console 1 5,120 K
java.exe 12636 Console 1 33,100 K
conhost.exe 14392 Console 1 5,220 K
ChsIME.exe 16240 Console 1 13,700 K
PowerCmd.exe 14980 Console 1 53,128 K
cmd.exe 14864 Console 1 6,324 K
conhost.exe 4876 Console 1 9,164 K
cmd.exe 200 Console 1 6,332 K
conhost.exe 15432 Console 1 6,544 K
cmd.exe 16276 Console 1 6,352 K
conhost.exe 10868 Console 1 6,520 K
cmd.exe 15252 Console 1 6,328 K
conhost.exe 16316 Console 1 6,652 K
java.exe 13676 Console 1 585,804 K
java.exe 9304 Console 1 65,792 K
java.exe 15352 Console 1 88,924 K
java.exe 8316 Console 1 68,084 K
WINWORD.EXE 4200 Console 1 80,792 K
SecureCRT.exe 14384 Console 1 43,312 K
chrome.exe 1388 Console 1 15,512 K
chrome.exe 1076 Console 1 88,620 K
chrome.exe 1684 Console 1 43,932 K
chrome.exe 6316 Console 1 40,980 K
chrome.exe 13708 Console 1 74,120 K
visualvm.exe 6480 Console 1 5,920 K
javaw.exe 10148 Console 1 121,552 K
jprofiler.exe 16224 Console 1 558,216 K
chrome.exe 9300 Console 1 43,528 K
chrome.exe 2368 Console 1 46,320 K
chrome.exe 12280 Console 1 47,424 K
chrome.exe 9652 Console 1 40,108 K
notepad++.exe 4060 Console 1 23,644 K
chrome.exe 10604 Console 1 67,932 K
taskhostw.exe 3216 Console 1 13,864 K
wwbizsrv.exe 1792 Services 0 10,988 K
LPlatSvc.exe 9936 Console 1 6,268 K
svchost.exe 544 Services 0 5,764 K
cmd.exe 11996 Console 1 7,460 K
conhost.exe 9940 Console 1 11,240 K
chrome.exe 1324 Console 1 69,424 K
chrome.exe 9484 Console 1 82,132 K
SearchProtocolHost.exe 10832 Services 0 13,680 K
cmd.exe 7364 Console 1 7,504 K
conhost.exe 8796 Console 1 11,136 K
SearchProtocolHost.exe 232 Console 1 7,912 K
chrome.exe 3520 Console 1 21,396 K
java.exe 10552 Console 1 107,688 K
java.exe 13444 Console 1 1,125,320 K
conhost.exe 8356 Console 1 9,820 K
conhost.exe 9408 Console 1 9,808 K
SearchFilterHost.exe 14588 Services 0 9,404 K
jmap.exe 15580 Console 1 27,840 K
tasklist.exe 1280 Console 1 9,284 K
- 使用
jmap
命令生成heap dump文件
C:\ProgramFiles\Java\jdk1.8.0_144\bin>jmap -dump:live,format=b,file=c:\dumptest\heap1.hprof 13444
Dumping heap to C:\dumptest\heap1.hprof ...
Heap dump file created
jprofiler
打开生成的heap1.hprof
文件
如上图所示,红色圈出来的即为占用内存最多的对象,也是最可能发生OOM问题的地方;
2. 使用 jcmd 命令生成 dump 文件
jcmd <pid> GC.heap_dump c:\dump\heap.hprof
3. 使用 JVM 参数获取 dump 文件
1. -XX:+HeapDumpOnOutOfMemoryError
当OutOfMemoryError发生时自动生成 Heap Dump 文件。
这可是一个非常有用的参数,因为当你需要分析Java内存使用情况时,往往是在OOM(OutOfMemoryError)发生时。
eg.



- -XX:+HeapDumpBeforeFullGC
当 JVM 执行 FullGC 前执行 dump。
- -XX:+HeapDumpAfterFullGC
当 JVM 执行 FullGC 后执行 dump。
- -XX:+HeapDumpOnCtrlBreak
交互式获取dump。在控制台按下快捷键Ctrl + Break时,JVM就会转存一下堆快照。
- -XX:HeapDumpPath=c:\test.hprof
指定 dump 文件存储路径。
注意:JVM 生成 Heap Dump 的时候,虚拟机是暂停一切服务的。如果是线上系统执行 Heap Dump 时需要注意。
4. 使用其它工具获取dump文件
分析 Heap Dump 的工具都可以获取 Heap Dump 文件。
比如:jdk 自带的工具 jvisualvm。
其它工具:Eclipse memory analyzer(jmat)、JProfiler 等。
2.mysql的索性数据结构,btree,b+tree,hash有什么不同。亿级数据库的表性能调优
3.spring cloud的各种组件,熔断的条件
4.spring boot的优点
5.项目做了哪些监控
6.MQ使用上遇到的问题
7.redis的使用场景,缓存,分布式锁如何释放,备份策略AOF,RDB
8.了解的rpc框架
9.http2.0和1.1的区别,tcp的三次握手,四次挥手。
1.项目介绍
2.java线程安全发生的原因,以及如何保障线程安全,以及问到jmm内存模型。
3.类加载机制,双亲委派机制,为什么使用双亲委派。以及如何打破双亲委派机制
4.谈谈自己理解的集合类和使用到的集合类,问到hashMap,以及concurrentHashMap的实现。阻塞队列的种类及其实现。问到红黑树及其实现。以及其时间复杂度
5.线程池的使用
6.spi的机制,以及目前哪些框架有使用
7.谈谈你理解的spring,及他的作用。
8.spring用到了哪些设计模式,分别是在哪用到的。
9.快速排序的实现原理。
做过的项目,挑一个有难度的讲讲
进一步询问简历上提到的开源组件,比如消息组件(Kafka RabbitMQ.、缓存组件(Redis.等,基本原理特点
MySQL索引(肯定会提到B+树,进一步询问B+树相关的原理.
进程与线程
MongoDB与MySQL的区别
数据库事务
Linux的命令,系统中实现IO多路复用的方式,各有什么区别和特点
给两个Linux命令,指出两个命令的区别
算法题,给定一个序列,求最长递增子序列有几个
数据结构方面,树要非常熟悉,二叉树/红黑树/b树/b+树等
数据库方面,索引/联合索引的实现原理,和使用规范
redis内存数据库支持的数据结构,底层实现原理
自己做过的项目,一定就精通,刨根到底的问
1、深挖分布式原理
2、二面继续深挖分布式,考察项目细节,针对项目现场画技术架构图和业务流程图,面试官会指出问题,并要求给出改进方案。
3、中间件实现业务的一致性的理解及实现方案
4、并发实现10到100到1000架构演进方案
5、MySQL性能调优
6、面试官喜欢有亮点的候选人,比如有自己的个人技术博客,对现场查看平时博客更新内容涉及到哪些方向。
说一说dubbo/Springcloud的原理
注册中心如何知道service的服务有变化
你认为这个长连接是由注册中心发起还是由service发起,为什么?
多线程如何保证
有哪些锁
C要等A,B两个线程跑完了才跑,用什么结构来实现,代码怎么写?有哪些手段
jdk中有哪些Map,线程安全数据结构有哪些
用concurrentHashmap如果对一个共享变量计数怎么写?
缓存与数据库如何保证一致性
如果查询和更新的场景同时到达怎么办?
有没有用过kafka,rocketmq如何保证消息一致性?
rocketmq如何保证有序的消息,批量的时候如何保证有序
批量的有序是rocketmq保证还是消费者保证
zookeeper一致性与zookeeper选举机制;
限流的算法有哪些,令牌桶和漏桶的应用场景,计数器限流会有什么问题;
dubbo负载均衡有哪些,讲讲一致性hash算法的实现;
netty对比nio有什么优点,讲讲select,poll,epoll;
activemq,kafka,rocketmq对比;
除了dubbo的其他rpc框架还了解哪些;
对比讲讲spring cloud和dubbo的区别;
多个服务调用链如何跟踪和监控的;
分布式全局唯一ID了解哪些,以及实现原理
聊下自己的近期的项目
有Java基础、JVM之类的
多线程,spring框架层面的东西
mysql、redis等数据库
MQ消息队列
主要问了Spring Bean的生命周期
Redis中jedis使用set值后的处理流程
微服务,docker,websocket, mysql,spring这些
kafka在消息爆涨后,消费端无法及时消费以后,如何在单机的情况下处理这些堆积的消息
JVM内存结构;
垃圾回收的算法,怎么确定一个对象要不要回收,作为Java回收时的root节点;
类加载机制,类加载器相关;
线程池参数和原理;
redis相关,缓存设置需要什么,Redis日志的两种格式,有何区别;
mysql索引数据结构,有哪几种日志,各自的作用是什么;
nio,aio,bio各自是什么,底层是怎么实现的;
一致性hash的原理。
1、JVM的内存结构,以及常用垃圾回收算法
2、类加载器双亲委派机制原理是什么?
3、Synchronized与ReentrantLock区别
4、AQS的原理
5、wait与notify的区别
6、AOF与RDB
7、BIO,NIO,AIO区别
8、线程池
9、redis set值之后逻辑流程,如何预防超卖
10、雪崩,穿透问题,如何解决。
1、什么是链表,链表有什么特点,使用链表有什么好处链表和数组有什么区别
2、说说你常用的排序算法,并说出他的时间复杂度和空间 复杂度
3、说说你知道的的查找算法有哪些,并如何实现的
4、说说快速排序和堆排序的实现过程
5、说出二分查找的实现过程和时间空间复杂度
6、哈希表知道吗,哈希表实现原理,如何处理哈希冲突
7、一颗二叉树从右边看过去,把看到的节点打印出来
8、0-1背包问题
9、判断两个字符串是否相等
10、快排的实现过程
1、N个数,找第K大数
2、找出两个子view最近的共同父view(算法.
3、给一个数组,求如何划分数组,使得abs(sum【A】 - sum【B】.最小,leetcode原题
4、给个有序数组,将数组非重复部分排在前面,不占用额外空间,输出数组
6、红黑树的特点是什么,什么情况下使用hashmap,什么情况下使用红黑树
1、给定一个二叉树和一个数字n,判断二叉树中是否有一个路径上的数字之和等于给定的数字n
2、二叉树翻转 (递归和迭代.
3、两条链表是否含有交叉
4、写一个迭代器
5、100万个16位整数,内存不限,找出Top K。
6、找出一个数组的长度 Top2 的连续升序子数组,并按长度降序输出
例如:
输入:[2, 1, 4, 5, 8, 3, 7, 10, 2, 5], k = 2
输出:[1, 4, 5, 8], [3, 7, 10]
7、给定一个序列,求最长递增子序列有几个(动态规划.
8、算法写个3sum(leetcode)
9、排序算法
10、实现一个单链表反转
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)