1.类继承与组合的区别与优缺点?
参考博文:https://blog.csdn.net/zymx14/article/details/79605926
补充:博文讲的很清晰,其实在我们的开发中,controller层使用service层,service层使用Dao层不就是一个组合的过程吗?通过将它们作为自身的属性,即has-a,而不是is-a的关系,不应该是继承关系,一个service是可以使用多个Dao层的,即把它们作为属性放进来。
2.1一个类中的两个方法都加了同步锁,多个线程能同时访问这个类的两个方法吗?
2.2两个线程一个访问静态方法,一个访问非静态方法,都加了锁会有什么问题?☆
参考博文:https://blog.csdn.net/weixin_40616523/article/details/87883267
补充:博文也很清晰,不过关于synchronized结论之一:一个类中的两个方法都加了同步锁,多个线程不能同时访问这个类的同一实例对象的两个方法。并不完全正确,也就是2.2的情况,虽然两个方法都加了锁,但是一个加了static关键字,一个没加,这意味着synchronized method1会把类对象锁起来,而synchronized method2锁的是该实例对象!因此多个线程是可以同时访问这两个方法的,因为它们锁的并不是一个对象!代码如下:
public class Example1 {
private static int num = 0 ;
public static synchronized void method1() {
System.out.println("同步方法1进入");
for(int i = 0 ; i<10 ; i++) {
System.out.print("同步方法1:"+num+"--");
num++ ;
}
System.out.println("同步方法1结束");
}
public synchronized void method2() {
System.out.println("同步方法2进入:");
for(int i = 0 ; i<10 ; i++) {
System.out.print("同步方法2:"+num+"--");
num++ ;
}
System.out.println("method2结束");
}
public static void main(String[] args) {
final Example1 example1 = new Example1() ;
Thread thread1 = new Thread(new Runnable() {
@Override
public void run() {
example1.method1();
}
}) ;
Thread thread2 = new Thread(new Runnable() {
@Override
public void run() {
example1.method2();
}
}) ;
thread1.start();
thread2.start();
}
}
输出结果:
同步方法1进入
同步方法2进入:
同步方法2:0--同步方法1:0--同步方法2:1--同步方法1:2--同步方法2:3--同步方法1:4--同步方法2:5--同步方法1:6--同步方法2:7--同步方法1:8--同步方法2:9--同步方法1:10--同步方法2:11--同步方法1:12--同步方法2:13--同步方法1:14--同步方法2:15--同步方法1:16--同步方法2:17--同步方法1:18--同步方法1结束
method2结束
3.序列化json如何排除一些字段?
参考博文:https://blog.csdn.net/yu870646595/article/details/78523402
4.https用到了什么方式加密?
参考博文:https://blog.csdn.net/qq_1290259791/article/details/82145476
5.链表怎么检查闭环?
参考博文:https://blog.csdn.net/weixin_40255793/article/details/80060243?utm_medium=distribute.pc_relevant_t0.none-task-blog-OPENSEARCH-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-OPENSEARCH-1.nonecase
6.hashmap会被gc吗?
参考博文:https://blog.csdn.net/simplebam/article/details/74135502
7.sql怎么防注入?
8.like可以用索引吗?
9.sql语句的执行顺序