1.java中为何会出现多线程?java
Java内存模型决定了 CPU 不能 彻底利用,为了充分利用CPU,因此产生了多线程技术。spring
2.多线程中,若是不调用start方法,直接调用run方法会发生什么?sql
只有调用Thread的start方法,将线程交由JVM控制,才能产生多线程,而直接调用run方法只是一个普通的单线程程式。 执行的是main主线程。数据库
3.为何会出现容器技术?编程
资源独立、隔离 ; 环境的一致性 ; 轻量化 ; Build Once, Run Everywhere 设计模式
4.若是java程序jvm内存分配很大会发生什么?安全
jvm的内存太小会致使频繁GC,过大会致使GC时间过长。内存越大,JVM 进行 Full GC 所需的时间越久,因为 Full GC 时 stop whole world 的 ,增长请求响应延迟。服务器
5.IO和NIO有什么区别?mybatis
Java BIO : 同步并阻塞,服务器实现模式为一个链接一个线程,即客户端有链接请求时服务器端就须要启动一个线程进行处理,若是这个链接不作任何事情会形成没必要要的线程开销,固然能够经过线程池机制改善。多线程
Java NIO : 同步非阻塞,服务器实现模式为一个请求一个线程,即客户端发送的链接请求都会注册到多路复用器上,多路复用器轮询到链接有I/O请求时才启动一个线程进行处理。
Java AIO(NIO.2) : 异步非阻塞,服务器实现模式为一个有效请求一个线程,客户端的I/O请求都是由OS先完成了再通知服务器应用去启动线程进行处理,
6.什么是微服务,你是怎么理解的?
微服务的所涉及的内容很是广,包括基础设施,也包括开发框架,开发、测试、运维都涵盖到了,它毫不是一款普通的架构。从开发框架来说,咱们应该灵活地选择最合适的编程语言和框架,从而实现具体的业务细节,而不要拘泥于在某一种技术上。
7.spring中@Transactional 的事务隔离级别有几种?
DEFAULT : 数据库的默认隔离级别
READ_UNCOMMITTED : dirty reads, non-repeatable reads and phantom reads
* can occur.便可能出现脏读,幻读,不可重复读
READ_COMMITTED : dirty reads are prevented; non-repeatable reads
* and phantom reads can occur.便可能出现幻读,不可重复读
REPEATABLE_READ :dirty reads and non-repeatable reads are
* prevented; phantom reads can occur. 便可能出现幻读
SERIALIZABLE :dirty reads, non-repeatable reads and phantom
* reads are prevented. 以上误读状况都被禁止
/** * Enumeration that represents transaction isolation levels for use * with the {@link Transactional} annotation, corresponding to the * {@link TransactionDefinition} interface. * * @author Colin Sampaleanu * @author Juergen Hoeller * @since 1.2 */ public enum Isolation { /** * Use the default isolation level of the underlying datastore. * All other levels correspond to the JDBC isolation levels. * @see java.sql.Connection */ DEFAULT(TransactionDefinition.ISOLATION_DEFAULT), /** * A constant indicating that dirty reads, non-repeatable reads and phantom reads * can occur. This level allows a row changed by one transaction to be read by * another transaction before any changes in that row have been committed * (a "dirty read"). If any of the changes are rolled back, the second * transaction will have retrieved an invalid row. * @see java.sql.Connection#TRANSACTION_READ_UNCOMMITTED */ READ_UNCOMMITTED(TransactionDefinition.ISOLATION_READ_UNCOMMITTED), /** * A constant indicating that dirty reads are prevented; non-repeatable reads * and phantom reads can occur. This level only prohibits a transaction * from reading a row with uncommitted changes in it. * @see java.sql.Connection#TRANSACTION_READ_COMMITTED */ READ_COMMITTED(TransactionDefinition.ISOLATION_READ_COMMITTED), /** * A constant indicating that dirty reads and non-repeatable reads are * prevented; phantom reads can occur. This level prohibits a transaction * from reading a row with uncommitted changes in it, and it also prohibits * the situation where one transaction reads a row, a second transaction * alters the row, and the first transaction rereads the row, getting * different values the second time (a "non-repeatable read"). * @see java.sql.Connection#TRANSACTION_REPEATABLE_READ */ REPEATABLE_READ(TransactionDefinition.ISOLATION_REPEATABLE_READ), /** * A constant indicating that dirty reads, non-repeatable reads and phantom * reads are prevented. This level includes the prohibitions in * {@code ISOLATION_REPEATABLE_READ} and further prohibits the situation * where one transaction reads all rows that satisfy a {@code WHERE} * condition, a second transaction inserts a row that satisfies that * {@code WHERE} condition, and the first transaction rereads for the * same condition, retrieving the additional "phantom" row in the second read. * @see java.sql.Connection#TRANSACTION_SERIALIZABLE */ SERIALIZABLE(TransactionDefinition.ISOLATION_SERIALIZABLE); private final int value; Isolation(int value) { this.value = value; } public int value() { return this.value; } }
8.spring中用到了那些设计模式,请举例说明?
工厂,动态代理(AOP),模板、装饰、单例、适配器等。如bean实例化预留的钩子可经过动态代理实现。
9.mybatis中$和#有什么区别?
#能够防止sql注入 $直接拼接值到sql语句中不安全 但 表名做为变量时,必须使用 ${ }