Steve
Steve
Deepak Lal wrote:
how should my Public static main method look like.I'm unable to figure that part for Scenario 1 and Scenario 2
SCJP6.0,My blog Ranchers from Delhi
SCJP6.0,My blog Ranchers from Delhi
OCPJP 85%
Deepak Lal wrote:
How should we synchronize the read and write method for static variable integer i.?Example provided will be helpful.
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Abimaran Kugathasan wrote:
Deepak Lal wrote:
How should we synchronize the read and write method for static variable integer i.?Example provided will be helpful.
Synchronization is for objects! Not to primitives!
Steve
Steve
Steve Luke wrote:
Abimaran Kugathasan wrote:
Deepak Lal wrote:
How should we synchronize the read and write method for static variable integer i.?Example provided will be helpful.
Synchronization is for objects! Not to primitives!
That is incorrect! You must protect primitives with synchronization as well, you just can't gain a lock on the primitive itself so you need to lock on something else.
Abimaran, this situation appears special ....
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Deepak Lal wrote:@Ranchers, @Steve I'm back with another scenario.see below
How should i apply synchronization for Scenario 4 such that read and write method are executed by 2 different threads. (as demonstrated by Joe lemmer in one of the posts) ?Sample code provided will be appreciated.
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
You have to lock on an Object which is available in the same contexts as the data you want to protect. For static content that generally means an Object stored in a static reference.
Steve
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Steve
Steve
Destroy anything that stands in your way. Except this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|