One Side of the Day---Real Interview Questions---2

Look at the original question first, meditate on the answer in your heart, and then slide to the back to compare the answer. The answer comes from the Internet, please correct me and make progress together

1. Original title

1. Self-introduction

2. The difference between Java and C

3. How does SpringBoot reflect encapsulation during development

4. Why does Java produce thread insecurity problems

5. How does the volatile keyword ensure visibility?

6. Does the declared local variable inside the method have thread safety issues?

7. HashMap specifies the size, how is it generally specified, and why is it 2 to the Nth power

8. Why are threads out of order

9. The difference between a primary key index and a non-primary key index

10. What is the non-primary key index and non-leaf storage? What is the leaf storage? How to avoid returning to the table

11. The scene of joint index abc joint index babcac that will go

12. What is the difference between timestamp and datetime for dates in MySQL

13. How to find your target address when the browser enters www.baidu.com

14. What are the solutions to the problems of Redis distributed locks

15.Springboot aop underlying implementation principle

16. Will there be a thing operation aop in a service for thing management will fail?

-------------------------------------------------- ----------------------Beautiful dividing line---------------------------- ------------------------------------------------

2. Answer

1. Self-introduction

2. The difference between Java and C

C语言:面向过程、编译型
Java语言:面向对象、混合型

3. How does SpringBoot reflect encapsulation during development

欢迎补充!!!

4. Why does Java produce thread insecurity problems

计算机系统资源分配的单位是进程,同一个进程中允许多个线程并发执行。并且多个线程会共享进程范围内的资源:例如内存地址。当多个线程并发访问同一个内存地址并且内存地址保存的值是可变的时候可能会发生线程安全问题,因此需要内存数据共享机制来保证线程安全问题。

5. How does the volatile keyword ensure visibility?

被volatile关键字修饰的变量,在每个写操作之后,都会加入一条store内存屏障命令,此命令强制工作内存将此变量的最新值保存至主内存;在每个读操作之前,都会加入一条load内存屏障命令,此命令强制工作内存从主内存中加载此变量的最新值至工作内存。

6. Does the declared local variable inside the method have thread safety issues?

局部变量线程安全

7. HashMap specifies the size, how is it generally specified, and why is it 2 to the Nth power

大小指定为2的N次方

1.提高计算效率; 
2. 减小Hash冲突的概率

9. Why are threads out of order

jvm为了使得处理器内部的运算单元能尽量被充分利用,处理器可能会对输入代码进行乱序执行(Out-Of-Order Execution)优化,处理器会在计算之后将乱序执行的结果重组,保证该结果与顺序执行的结果是一致的,但并不保证程序中各个语句计算的先后顺序与输入代码中的顺序一致,因此,如果存在一个计算任务依赖另外一个计算任务的中间结果,那么其顺序性并不能靠代码的先后顺序来保证

10. The difference between a primary key index and a non-primary key index

非主键索引的叶子节点存放的是主键的值,而主键索引的叶子节点存放的是整行数据;
其中非主键索引也被称为二级索引,而主键索引也被称为聚簇索引;

11. Non-primary key index, what is stored in non-leaf, what is stored in leaf, and how to avoid returning to the table

欢迎补充!!!

12. The scene of joint index abc joint index babcac that will go

ac

13. The difference between timestamp and datetime for dates in MySQL

1、datetime的默认值为null,timestamp的默认值不为null,且为系统当前时间(current_timestatmp)。如果不做特殊处理,且update没有指定该列更新,则默认更新为当前时间。

2、datetime占用8个字节,timestamp占用4个字节。timestamp利用率更高。

3、二者存储方式不一样,对于timestamp,它把客户端插入的时间从当前时区转化为世界标准时间(UTC)进行存储,查询时,逆向返回。但对于datetime,基本上存什么是什么。

4、二者范围不一样。timestamp范围:‘1970-01-01 00:00:01.000000’ 到 ‘2038-01-19 03:14:07.999999’; datetime范围:’1000-01-01 00:00:00.000000’ 到 ‘9999-12-31 23:59:59.999999’。原因是,timestamp占用4字节,能表示最大的时间毫秒为2的31次方减1,也就是2147483647,换成时间刚好是2038-01-19 03:14:07.999999。

14. How to find your target address when the browser enters www.baidu.com

客户端浏览器通过DNS解析到www.baidu.com的IP地址220.181.27.48,通过这个IP地址找到客户端到服务器的路径。客户端浏览器发起一个HTTP会话到220.161.27.48,然后通过TCP进行封装数据包,输入到网络层

15. What are the solutions to the problems of Redis distributed locks

问题:
    1 锁需要具备唯一性
    2 锁需要有超时时间,防止死锁
    3 锁的创建和设置锁超时时间需要具备原子性
    4 锁的超时问题
    5 锁的可重入问题
    6 集群下分布式锁的问题

解决方案
	1、使用redis命令setnx(set if not exist),即只能被一个客户端占坑,如果redis实例存在唯一键(key),如果再想在该键(key)上设置值,就会被拒绝.

	2、为了避免客户端挂掉或者说是客户端不能正常释放锁的问题,需要在加锁的同时,给锁加上超时时间.即加锁和给锁加上超时时间的操作

	3、set lockkey true ex 5 nx命令可以一次性完成setnx和expire两个操作,也就是解决了原子性问题.

	4、客户端可以在锁设置成功之后,进行定时任务,在锁超时之前使用lua脚本删除锁并重新设置锁和超时时间.

	5、我们可以选择使用lua脚本的方案,将锁重新删除和设置.

	6、

16.Springboot aop underlying implementation principle

欢迎补充

17. In a service, there is a thing operation aop for thing management will it fail

会失效