趋势面试
这次面试可以学到很多东西,认识到自己还有很多的不足,面试官即兴发挥,不会按照所谓的八股文面试,自己面的很烂,还是得多学习!
- 线程如何创建?
1. 继承Thread类,重写run方法;
2. 实现Runnable接口,重写run方法,并将类实例作为Thread的构造参数;
3. 现象Callable接口,重写run方法,通过FutureTask类构造一个Runnable的子类实例,作为Thread的构造参数;
4. 通过线程池创建,Executors的工厂方法。
- 如何实现线程的定时任务?
/**
* 每周四18:00定时执行任务
* 要点是initialDelay的设置
* */
public class ScheduledExecutorServiceDemo02 {
public static void main(String[] args) {
LocalDateTime now = LocalDateTime.now();//获取当前时间
long period = 1000 * 60 * 60 * 24 * 7; //每周时间间隔
LocalDateTime time = now.withHour(18).withMinute(0).withSecond(0).withNano(0).with(DayOfWeek.THURSDAY);//获取周四18:00时间
if(now.compareTo(time)>0){ //如果当前时间过了周四,就加一周,下周执行
time = time.plusWeeks(1);
}
long initialDelay = Duration.between(now, time).toMillis();
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
scheduledExecutorService.scheduleAtFixedRate(()->{
//执行的定时任务
System.out.println("定时任务");
},initialDelay,period, TimeUnit.MILLISECONDS);
}
}
- springboot如何对大规模的API增加异常处理(全局)?
- springboot监听器、过滤器、拦截器应用场景?
- 如何对hashmap数据进行排序?
- springboot怎么实现日志回滚
- 全局异常处理怎么添加?
使用 AOP+通配符,对于多个API的情况下,不用一个个手动去添加