独立Java应用程序中内存更改的事务管理

时间:2021-10-28 20:57:45

I have a standalone java application in which one function call from the GUI will result in multiple changes in instance variables of different classes.We want to write a transaction manager for this so that if some exception is thrown then changes done in memory prior to execution block are reverted.We can surely do it a naive way by creating a copy of instance variable before the call , and reverting the changes if exception occurs , but i am looking for some sophisticated and a good design to handle this problem.

我有一个独立的java应用程序,其中来自GUI的一个函数调用将导致不同类的实例变量的多个更改。我们想为此编写一个事务管理器,以便如果抛出一些异常,那么在执行之前在内存中完成更改通过在调用之前创建实例变量的副本,并且如果发生异常则还原更改,我们可以确定这是一种天真的方式。但我正在寻找一些复杂的和良好的设计来处理这个问题。

Please let me know if any one has idea of some framework or generic design that can be used to solve this problem.

如果有人知道某些框架或通用设计可以用来解决这个问题,请告诉我。

2 个解决方案

#1


0  

You can use the Memento design pattern to store the state of the objects. If everything goes fine, you delete the last stored state. If there is some problem, you restore the last state. Here is a reference (a poor one) http://en.wikipedia.org/wiki/Memento_pattern. Try Google for more details.

您可以使用Memento设计模式来存储对象的状态。如果一切顺利,您将删除最后存储的状态。如果出现问题,请恢复上一个状态。这是一个参考(一个可怜的)http://en.wikipedia.org/wiki/Memento_pattern。试试Google了解更多详情。

The Memento works similarly of what you said, but it formalizes an architecture to provide this feature.

Memento的工作方式与您所说的类似,但它正式化了一个架构来提供此功能。

Here is the classical reference: http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=sr_1_1?ie=UTF8&qid=1342931128&sr=8-1&keywords=design+patterns

以下是经典参考:http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=sr_1_1?ie=UTF8&qid=1342931128&sr=8-1&keywords=design+patterns

#2


0  

Cloning (by cloning / serialization & deserialization or another mechanism) the object to a transactional view and propagating the state back to the (hidden) committed instance (combint with an optimistc locking mechanism based on version counters) is a common approach. (It is e.g. used by https://github.com/JanWiemer/jacis transactional object store...)

将对象克隆(通过克隆/序列化和反序列化或其他机制)到事务视图并将状态传播回(隐藏)提交的实例(具有基于版本计数器的optimistc锁定机制的组合)是一种常见的方法。 (例如,由https://github.com/JanWiemer/jacis事务对象存储使用...)

#1


0  

You can use the Memento design pattern to store the state of the objects. If everything goes fine, you delete the last stored state. If there is some problem, you restore the last state. Here is a reference (a poor one) http://en.wikipedia.org/wiki/Memento_pattern. Try Google for more details.

您可以使用Memento设计模式来存储对象的状态。如果一切顺利,您将删除最后存储的状态。如果出现问题,请恢复上一个状态。这是一个参考(一个可怜的)http://en.wikipedia.org/wiki/Memento_pattern。试试Google了解更多详情。

The Memento works similarly of what you said, but it formalizes an architecture to provide this feature.

Memento的工作方式与您所说的类似,但它正式化了一个架构来提供此功能。

Here is the classical reference: http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=sr_1_1?ie=UTF8&qid=1342931128&sr=8-1&keywords=design+patterns

以下是经典参考:http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=sr_1_1?ie=UTF8&qid=1342931128&sr=8-1&keywords=design+patterns

#2


0  

Cloning (by cloning / serialization & deserialization or another mechanism) the object to a transactional view and propagating the state back to the (hidden) committed instance (combint with an optimistc locking mechanism based on version counters) is a common approach. (It is e.g. used by https://github.com/JanWiemer/jacis transactional object store...)

将对象克隆(通过克隆/序列化和反序列化或其他机制)到事务视图并将状态传播回(隐藏)提交的实例(具有基于版本计数器的optimistc锁定机制的组合)是一种常见的方法。 (例如,由https://github.com/JanWiemer/jacis事务对象存储使用...)