dcsimg
Synchrinization
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Manish_Sharma
Posted On:   Wednesday, July 30, 2003 03:11 AM

If we put the same code in three different ways using synchronization, what will be the difference when code is executed?


			
Type-1
public void test() {
synchronize {
code ....//code
}
{

Type-2
synchronize public void test() {
code ...//code
}

Type-3
public void test() {
synchronize(temp) {
code ....//code
}
{


Note: Piece of code mentioned above is same in all three case.

Re: Synchrinization

Posted By:   Anonymous  
Posted On:   Wednesday, July 30, 2003 05:02 AM

Type-1


public void test() {
synchronize {
code ....//code
}
{


All the code in the 'synchronize' block is synchronized.


Type-2


synchronize public void test() {
code ...//code
}


All the code in the test() method is synchronized.


Type-3


public void test() {
synchronize(temp) {
code ....//code
}
{


All the code in the temp object is synchronized(only within the 'synchronize' block).


Which type to use?

Depends on the logic. More the synchronized code, more would be the performance degrade.

Hope its clear.........
About | Sitemap | Contact