Patterns in JavaTM, Volume 3 Java Enterprise Java Enterprise Design Patterns phần 8

danh sách các giao diện TransactionParticipantIF. Tất cả các đối tượng tham gia trong một giao dịch phải trực tiếp thực hiện các giao diện TransactionParticipantIF hoặc được bao bọc bởi một đối tượng bộ chuyển đổi thực hiện các giao diện | 342 Chapter Seven listing of the TransactionParticipantIF interface. All objects that participate in a transaction must either directly implement the Transaction-ParticipantiF interface or be wrapped by an adapter object that implements the TransactionParticipantiF interface. public interface TransactionParticipantIF This method does not return until it can associate a lock on the participating object with the current thread. public void lock Return an object that encapsulates the state of the participating object. public SnapshotIF captureState Restore the state of the participating object from the information encapsulated in the given object. The given object must have previously been returned by this object s captureState method. public void restoreState SnapshotIF state Release a previously obtained lock. public void unlock interface TransactionParticipantiF Here is a listing of the TransactionManager class. An interesting thing about the TransactionManager class is that it delegates most of its work to a private inner class called Transaction. When a transaction is started a TransactionManager object creates and associates a Transaction object with the current thread. This organization is based on the assumption that transactions are single-threaded. Every time a TransactionManager object is asked to do something it uses the Transaction object that it previously created for the current thread. public class TransactionManager private ThreadLocal myStack private ThreadLocal currentTransaction The myStack instance variable associates a Stack object with the current thread. The stack is used to save the values of objects when they are locked. The currentTransaction instance variable associates the current transaction a thread is working on with that thread. If the transaction is Concurrency Patterns 343 nested in another transaction its enclosing transaction is saved on the stack. The TransactionManager class s constructor initializes these variables. public .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.