• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

How to implement own TransactionManagment

 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
You save more money with a clothesline than dozens of light bulb purchases. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic