interview questions

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語句中不安全  但 表名做爲變量時,必須使用 ${ }

相關文章
相關標籤/搜索