天天看點

事務和Java和Hibernete和Spring

基礎知識

Isolation

​​【資料庫】快速了解髒讀、不可重複讀、幻讀​​

  • 讀取未送出(Read uncommitted):處于此模式下可能會出現髒讀、幻象讀、不可重複讀
  • 讀取已送出(Read committed):處于此模式下可能會出現幻象讀、不可重複讀
  • 可重複讀(Repeatable read):處于此模式下可能會出現幻象讀
  • 串行(Serialize):不會出現幻象讀

Local Transaction & Global Transaction

Transaction(事務) 分兩種 Local Transaction 和 Global Transaction 涉及到一個Connection的Commit,稱為Local Transaction 涉及到多個Connection的Commit,稱為Global Transaction

Spring Tx

TransactionDefinition中可以指定了如下資訊

Propagation:傳播方式,參考​​tx-propagation​​Isolation:隔離級别;指定目前事務與其他事務隔離的級别;Isolation有四個有效值,ISOLATION_READ_UNCOMMITTED,ISOLATION_READ_COMMITTED,ISOLATION_REPEATABLE_READ,ISOLATION_SERIALIZABLE,如果指定目前事務的隔離級别為ISOLATION_READ_UNCOMMITTED,則目前事務可以看到其他事務未送出的内容;同理,如果指定事務隔離級别為ISOLATION_READ_COMMITTED,則隻能看到其他事務已經送出的内容;如果指定事務隔離級别為ISOLATION_REPEATABLE_READ,則會等待其他事務釋放行級鎖;如果指定事務隔離級别為ISOLATION_SERIALIZABLE,則會等待其他事務釋放表級鎖;

Timeout:指定,在事務逾時而被底層事務基礎設施復原之前,運作了多長時間

Read-only:當業務代碼隻讀取而不修改資料時,可以使用一個read-only transaction,在這種情況下,Read-only transaction可以做很多有用的優化;

Spring Integration

MessageChannel

MessageChannel that decouples message producers from message consumers.Message channels may or may not buffer messages .

public interface MessageChannel {

    boolean send(Message message);

    boolean send(Message message, long timeout);
}      

可以往MessageChannel中發送消息,但是根據message channels是否可以緩存message,從MessageChannel中接收消息有兩種方式,PollableChannel和SubscribableChannel;

Channel Adapter

A channel adapter is an endpoint that connects a message channel to some other system or transport.

Channel adapters may be either inbound or outbound.

Channel Adapter和InboundGateway的差別?

These inbound endpoints consist of two components: the poller configuration, to initiate the polling task periodically, and a message source class to read data from the target protocol and produce a message for the downstream integration flow.

Listening components can be one-way MessageProducerSupport implementations, (such as AbstractMqttMessageDrivenChannelAdapter and ImapIdleChannelAdapter) or request-reply MessagingGatewaySupport implementations (such as AmqpInboundGateway and AbstractWebServiceInboundGateway).

ChannelAdapter有inbound和outbound之分,但都是單向的,Gateway是雙向的,既可以接收消息,又可以回複消息;

Message Publishing

調用@Publisher注釋的方法,他就會發送message到指定的channel

MessageDispatcher

MessageDispatcher用來分發消息,有BroadcastingDispatcher和UnicastingDispatcher兩種,BroadcastingDispatcher發給多個,UnicastingDispatcher隻發給一個監聽者;

MessageHandler

org.springframework.messaging.MessageHandler. The goal of the implementation of this interface is to handle the message consumed by the endpoint from the channel.

All EIP components in Spring Integration are MessageHandler implementations (for example, AggregatingMessageHandler, MessageTransformingHandler, AbstractMessageSplitter, and others).

The target protocol outbound adapters (FileWritingMessageHandler, HttpRequestExecutingMessageHandler, AbstractMqttMessageHandler, and others) are also MessageHandler implementations.

The MessageHandler implementations represent the outbound and processing part of the message flow.

MessageProducerSupport&MessagingGatewaySupport

The inbound message flow side has its own components, which are divided into polling and listening behaviors. The listening (message-driven) components are simple and typically require only one target class implementation to be ready to produce messages. Listening components can be one-way MessageProducerSupport implementations, (such as AbstractMqttMessageDrivenChannelAdapter and ImapIdleChannelAdapter) or request-reply MessagingGatewaySupport implementations (such as AmqpInboundGateway and AbstractWebServiceInboundGateway).