what is synchoronization in java?

hello friends i am new to javacan any body help mewhat is synchoronization in java?
[118 byte] By [jesus789a] at [2007-11-27 4:15:07]
# 1
http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html http://java.sun.com/docs/books/tutorial/essential/concurrency/sync.html
hiwaa at 2007-7-12 9:21:27 > top of Java-index,Java Essentials,New To Java...
# 2

Hi,

Synchronization means, it allows only one thread to access the instance.

For Example.-

public class Counter

{

int c = 0;

public void A()

{

c++;

}

public void B()

{

c--;

}

In above example, first time c is going to increment and second time c is going to decrement.

Unless you declare synchronization for these two methods, the result leaves to inconsistency.

We use two types of synchronization.

Using Synchronization keyword with method.

and synchronization block

synchronization

{

// some code here.

}

In two things, second one means synchronization block is best.

Thanks and Regards

Maruthi.

mars@sayampua at 2007-7-12 9:21:27 > top of Java-index,Java Essentials,New To Java...