记百度面试
记百度面试_20211115
根据回忆,还原了下面试题
视频面试,很直接,直接上题
题1:JVM
从类加载讲起
import java.lang.reflect.Constructor;
public class Test {
public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException {
Student student1 = new Student();
student1.setName("张三");
Student student2 = new Student();
student2.setName("张三");
student1 = null;
System.gc();
Class<Student> clazz = (Class<Student>) Class.forName("Test.Student");
Constructor<Student> constructor = clazz.getConstructor(String.class);
}
static class Student {
private String name;
public Student() {
}
public Student(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
// jdk1.8默认垃圾回收器
// CMS
// G1
}
题2:多线程
多线程下返回值?线程安全的吗?你理解的线程安全
import java.util.ArrayList;
import java.util.List;
public class Test {
public static void main(String[] args) {
method1(123);
}
public static List method1(int id) {
List list1 = new ArrayList();
list1.add(id++);
return method2(list1);
}
private static List method2(List list1) {
List list2 = new ArrayList();
list2.addAll(list1);
list2.remove(list1);
return list2;
}
}
题2.5:线程
以下代码有问题吗?为什么?
public class Test {
public static void main(String[] args) {
Thread thread = Thread.currentThread();
while (true) {
if (thread.isInterrupted()) {
break;
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
题3:锁的升级过程
题3.5:CAS原理
题4:网络IO模型
bio、nio、aio、selector、poll、epoll
题5:组件/中间件
Redis集群、Master选举算法、MongoDB、ES算法、RocketMQ/Kafka等

浙公网安备 33010602011771号