snippetjournal

– notes, snippet codes, and my journal

Archive for September 2012

“pessimistic locking” and “optimistic locking.”

leave a comment »

Pessimistic Locking :
Pessimistic locking is when a transaction occurs, and then the resource is locked from the time it is first accessed. Until the transaction finished another transaction cant accessed the resources.

Optimistic Locking :
Optimistic locking applied a fail safe way. The state of resource is locked as soon the transaction occurs. But when another transaction occurs and attempting to accessed the resource it will result a delayed. Until the first accessed resources finished and unlock the resources.
The lock exists until the transaction committed or rolled back. If the resource is released. It will be compare the state which has been changed to the state when the time its locked. If the state differ it will rolled back the resource.

It compare the state of resource instead compare the changed data.
Some article defined a state as a version.

http://docs.jboss.org/jbossas/docs/Server_Configuration_Guide/4/html/TransactionJTA_Overview-Pessimistic_and_optimistic_locking.html

Written by snippetjournal

September 29, 2012 at 2:02 pm

“pass by value” and “pass by reference” In JAVA

leave a comment »

• What is the difference between “pass by value” and “pass by reference”? How are these ideas different in object-oriented systems and procedural systems?

Pass by value :
Pass by value mean it passing a copy of the value to be passed.
If a variable is passed, the variable receives the copy of the variable value. The value of the original variable can’t be changed within this method, because the variable which passed only has a copy of value from the original variable.

Pass by reference
Pass by reference mean it passing a reference of address in memory.
When it comes to object, it mean passing by references to an object.

Note for JAVA:
Java does manipulates object by reference, and all object variables are references.
However, java doesn’t pass method arguments by reference. It passes them by value.
http://www.javacertificate.net/passbyvalue.htm
http://www.javaworld.com/javaqa/2000-05/03-qa-0526-pass.html
http://javapapers.com/core-java/java-pass-by-value-and-pass-by-reference/
http://www.javacertificate.net/passbyvalue_1.htm

Written by snippetjournal

September 29, 2012 at 2:00 pm

Posted in Programming

Tagged with , , ,

Difference Between Equality and Equivalence

with 2 comments

what is the difference between Equality and Equivalence :
a variable can be equal when a value of variable are the same. example of equal variable but doesn’t equivalent  :

int a = 3;
double b = 3.0;

variable a is equal to variable b, but the both variable are not equivalent, because each variable represent the different type.

variable a represent integer type, and variable b represent the double type.

example of equal variable and equivalent variable:

int a = 3;int b = 3;

variable a and variable b are equal and equivalent, because both variable has the same value and data type, integer type

equality or equal is about symbol = , equivalent is about symbol >, <
example :

a = 3;
b = 3;

a = b (a is equal or equality with b)

Written by snippetjournal

September 29, 2012 at 1:57 pm

Posted in Programming

Tagged with ,