tag:blogger.com,1999:blog-8712770457197348465.post2287873022343814054..comments2024-03-29T05:54:46.190-07:00Comments on Javarevisited: Avoid Mixing static and non static synchronized method - Java mistake 2 Examplejavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-8712770457197348465.post-67785091770383016292017-03-01T03:38:55.567-08:002017-03-01T03:38:55.567-08:00In case of non static synchronized method lock wil...In case of non static synchronized method lock will be acquired by the object(this) and in case of static synchronized lock will be acquired by class.Inderjeethttps://www.blogger.com/profile/16395819390410076834noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-36852433867461044902015-10-05T13:04:34.209-07:002015-10-05T13:04:34.209-07:00Can you clear me concept? How can you say it's...Can you clear me concept? How can you say it's java mistake? may be it could be feature that... t1.obj t2.obj can are synchronized... but t3 could be not... suppose t3 want to check modification/value of one field each neno sec then?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-41629185593927740272013-01-16T05:58:53.245-08:002013-01-16T05:58:53.245-08:00So, I see what is wrong (two different versions of...So, I see what is wrong (two different versions of locking), but what is the best way of going about fixing this? Would this be the optimal solution: <br /><br />public int getCount(){<br /> synchronize(*.class) {<br /> return count;<br /> }<br /> return count;<br /> }Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-15468242840470320572013-01-10T01:18:18.693-08:002013-01-10T01:18:18.693-08:00I think one of the main difference between synchro...I think one of the main difference between synchronized method and static synchronized method is locking, former is locked on this object while later is locked on Class.class literal object. There can be only one class lock in case of static synchronized method but there can be multiple lock on synchronized method. Only one thread can execute static synchronized method at a time because its on Anonymousnoreply@blogger.com