Friends,
I have a query regarding the use of 'synchronized' keyword in a programme. This is mainly to check if there's any difference in the use of 'static' keyword for synchronized methods. By default we cannot call two synchronized methods from a programme at the same time. For example, in 'Program1', I am calling two methods, 'display()' and 'update()' both of them are synchronized and the flow is first, 'display()' is called and only when display method exits, it calls the 'update()' method.
But, things seem different, when I added 'static' keyword for 'update()' method as can be seen from 'Program2'. Here, instead of waiting for 'display()' method to finish, 'update()' method is called during the execution of 'display()' method. You can check the output to see the difference.
Does it mean, 'static' keyword has anything to do with synchronizaton?
Appreciate your valuable comments.
1. Program1
Output:
Synchronized methods
test:
start display:
end display:
start update:
end update:
2. Program2
Output:
Synchronized methods test:
start display:
start update: end update:
end display:
Edit by mw: Added
Code Tags.
[ June 19, 2008: Message edited by: marc weber ]