Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Friday, January 29, 2016

How to explain atomic actions?

How to explain atomic actions?


Hi I am just trying to answer this question but not sure if my answer is correct, has anyone any better way of explaining an atomic action?

Question:

In a concurrent system it is necessary to implement atomic actions. Explain what atomic actions are and why they are neccessary. How are atomic actions implemented in Java?

My Answer:

In programming an atomic action is one that effectively happens all at one. An atomic action cannot stop in the middle it either happens completely or not at all.

An example,

Ordering an airline ticket online where two actions are required: payment and a seat reservation. The potential passenger must either.

  1. both pay and reserve a seat, OR
  2. niether pay nor reserve a seat

How are atomic actions implemented in Java?

Im not sure how to answer this?

Answer by Batsu for How to explain atomic actions?


well, is not that an atomic action cannot be stopped in the middle. Is more: all his effects become visible when the action is completed (commit) or are not visible at all (abort/rollback); so it can be stopped, but the state of the system is not updated.

Answer by Robin for How to explain atomic actions?


By reading the Java tutorial on Atomic Access

Answer by JB Nizet for How to explain atomic actions?


Your explanation, IMHO, rather explains what atomicity means regarding database transactions: the A in ACID.

Regarding concurrency, atomicity rather means that when a thread modifies the state of some object (or set of objects), another thread can't see any intermediary state. Either it sees the state as it was before the operation, or it sees the state as it is after the operation.

For example, changing the value of a long variable is not an atomic operation. It involves setting the value of the 32 first bits, and then setting the state of the 32 last bits. If the access to the long variable is not properly synchronized, a thread might see the intermediary state: the 32 first bits have been changed, but the 32 last bits haven't been changed yet.

The way to implement atomic operations is to use synchronization. synchronization involves using

  • the synchronized keyword
  • the volatile keyword
  • atomic variables (AtomicInteger, etc.)

Answer by Roger for How to explain atomic actions?


Maybe you should think about transactions. Make some process but do not save changes until everything is in order. Like when you are withdrawing money from a machine, you follow a series of steps, before seeing changes on your account, i.e. Put your card, your password, say how much money you want, receive the money. If something fails in one of the steps, you dont see changes in your savings account, e.g. your password was incorrect, or you are trying to withdraw more money than what you have...

You can read the java tutorial. http://docs.oracle.com/javase/tutorial/essential/concurrency/atomic.html

Answer by Sai Teja for How to explain atomic actions?


Atomicity-when a trascation is interrupted or failure occurs in between..we need to ensure atomicity which means in a transaction either all statements are executed or none of them are executed......like if a trasctn has 5 stmnts...if a filure occurs in btw then atomcty means that either 5 stmts r exctd or none of them exctd....


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.