Java Interview ---- affairs

Java Interview ---- affairs

 

1. What is a transaction?

  It is the smallest unit of work transaction database operations, a series of operations as a single logical unit of work performed; these operations as a whole is submitted to the system together, are either executed or not executed; transaction is a collection operation can not be subdivided ;

2. What are the four characteristics of the transactions is? ------ ACID

  Atomicity: All operations included a firm is an indivisible whole, they are either fully executed successfully committed or rolled back completely fails

  Consistency: the implementation of the outcome of the transaction database must be converted from one consistent state to another consistent state

  Isolation: Each transaction execution are independent, concurrent execution of each transaction can not interfere with each other

  Sustainability: Once you have submitted the transaction, change its database is permanent

How 3.jdbc operating Affairs

  JDBC Connection by operating Affairs

  try{

    conn.getTranscationIsolation () // method to set the isolation level

    conn.getAutoCommit (false) // method to turn off automatic submission

    Execute multiple SQL

    conn.commit () // are successful, the transaction is committed

  }catch(){

    Execution fails, catch the exception

    conn.rollback () // rollback

  } finally{

    conn.commit () // finally submit it

  }

 

How 4.Spring operating affairs?

  Spring is not the direct management of affairs, but offers a variety of transaction manager, so that the platform framework mechanism provided by the persistence of the transactions to implement transaction management.

  Spring management services primarily through three interfaces:

  PlatformTransactionManager   : Spring transaction management is the core of the interface. The main function of the transaction manager, is the management platform for related matters, including matters submitted to commit; rollback rollback transaction; acquiring three methods getTransaction state of affairs.

  TransactionDefinition:  The main function is to define transaction information

  TransactionStatus: The main function of specific operational status of the transaction is a transaction management process, status information for each transaction point in time, it can encapsulate a lot of code, save our workload.

 

     Spring transaction management into programmatic and declarative transaction Affairs

  Programmatic transaction: the transaction management code is embedded to control the business process transaction commit and rollback, the transaction management program which must include additional code for transaction management, cumbersome, inconvenient operation at each transaction.

  Declarative transaction: is based on AOP. Its essence is to intercept method before and after, and then create or join a transaction before the target method begins, commit or roll back the transaction in accordance with the implementation after executing the target method. The biggest advantage is that without going through declarative transaction

  Programmatically manage the transaction, so that no doping transaction management code in the business logic code, just based on the way @Transactional annotation or configuration files associated with the transaction rule states do, it can be applied to business through business rules logic.

 

  Problems caused by concurrent transactions:

  1. dirty read

  4. Modify loss

  2. Magic Reading

  3. Non-repeatable read

 

  Concurrent transaction isolation level:

  ransactionDefinition interface defines five levels of isolation represent constants:

  ISOLATION_DEFAULT:  Use the default isolation level back-end database, Mysql default isolation level used REPEATABLE_READ Oracle defaults of READ_COMMITTED isolation level.

  ISOLATION_READ_UNCOMMITTED:  lowest isolation level, allowing the data to change the reading has not been submitted, may cause dirty reads, non-repeatable reads or phantom reads

  ISOLATION_READ_COMMITTED:  allow concurrent transactions to read data already submitted, can prevent dirty reads, but phantom reads or non-repeatable read may still occur

  ISOLATION_REPEATABLE_READ:  repeatedly reading the results of the same field are the same, unless the data is modified their affairs themselves, you can prevent dirty reads and non-repeatable reads, but phantom reads still occur.

  ISOLATION_SERIALIZABLE: the highest level of isolation, full compliance ACID isolation levels. All transactions executed one by one in sequence, it is impossible to produce interference between such matters, that is to say, the level

  Possible to prevent dirty reads, non-repeatable read and phantom read. But this will seriously affect the performance of the program. Under normal circumstances you do not need this level.

  The propagation of spring transaction total is divided into the following (according to the meaning in mind):

  1. REQUIRED(常用)
  2. REQUIRES_NEW(常用)
  3. SUPPORTS
  4. NOT_SUPPORTED
  5. NEVER
  6. NESTED
  7. MANDATORY

   Other properties of transactions:

    Property transaction timeout: Set by TransactionDefinition. The maximum time of transaction execution, timeout rollback

    Transaction read-only attribute: by setting TransactionDefinition. On transactional resources or read-only operations and write. The so-called transactional resources refers to those transaction management resources, such as data source,

           JMS resources, and custom transactional resources and so on. If it is determined only transactional resource for read-only operation, then we can be marked as read-only transactions, in order to improve the performance of the transaction.

    Rollback rules: By default, the transaction only encounter runtime exception will be rolled back and not be rolled back in the face of checked exceptions.

    

Guess you like

Origin www.cnblogs.com/Saber-Altria/p/11693405.html