wood burning stoves*
The moose likes Java in General and the fly likes How to implement own TransactionManagment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to implement own TransactionManagment" Watch "How to implement own TransactionManagment" New topic
Author

How to implement own TransactionManagment

walter wang
Ranch Hand

Joined: Jun 02, 2001
Posts: 154
I had a java application ( desktop application, standalone program)

How could I implement my own TransactionManagment for it?
my application doesnot do anything with Database.


Could anyone give some hints?


public class Walter { public boolean is_Working_Now (boolean is_boss_Coming) { return is_boss_Coming; }
Jeff Storey
Ranch Hand

Joined: Apr 07, 2007
Posts: 230
Hi Walter,

You should look into using synchronization or locks. They allow you to "protect" code so only one thread can enter it at a time. Consider this:



In this case, either all of method A will run before method B or the other way around (depending on which thread actually starts first, a or b). Since both methods are synchronized, only one thread can hold the lock at any given time. Check out this example. http://www.d.umn.edu/~gshute/java/synchronization.html.

Hope this helps.

Jeff
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

walter:
How could I implement my own TransactionManagment for it?

Well Transaction management is a big big monster. No one can explain it to you in a single post.
If you want to write your own Transaction Management then it is better to follow JTA and JTS.


walter:my application doesnot do anything with Database.


Well transaction management does not always deal with database handling. Transactions is a way to guarantee ACID(Atomicity, Consistency, Isolation and durability) properties. It can be applied to any system and any process.

For example in my POJO I can call two methods, such that, the second method is called only if the first succeed and if the second fails the result of the first operation must be reverted.
Even if the above methods do not make any database calls or any other data persistance calls, it still can be addressed by Transaction Management.


apigee, a better way to API!
walter wang
Ranch Hand

Joined: Jun 02, 2001
Posts: 154
Originally posted by Jeff Storey:
Hi Walter,

You should look into using synchronization or locks. They allow you to "protect" code so only one thread can enter it at a time. Consider this:



In this case, either all of method A will run before method B or the other way around (depending on which thread actually starts first, a or b). Since both methods are synchronized, only one thread can hold the lock at any given time. Check out this example. http://www.d.umn.edu/~gshute/java/synchronization.html.

Hope this helps.

Jeff


Thanks for your suggestion. yeah. it solves the synchronization problem,but how it handle rollback when excpetion happens?...
example rollback deleted files..or...
walter wang
Ranch Hand

Joined: Jun 02, 2001
Posts: 154
Originally posted by Nitesh Kant:


Well transaction management does not always deal with database handling. Transactions is a way to guarantee ACID(Atomicity, Consistency, Isolation and durability) properties. It can be applied to any system and any process.

For example in my POJO I can call two methods, such that, the second method is called only if the first succeed and if the second fails the result of the first operation must be reverted.
Even if the above methods do not make any database calls or any other data persistance calls, it still can be addressed by Transaction Management.


>>>> could you please give me some hints (sample code) for your mentioned roll back feature? it is just what I am looking for....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to implement own TransactionManagment