This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to implement own TransactionManagment

 
walter wang
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jeff Storey
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
walter wang
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic