tag:blogger.com,1999:blog-4213799477897003979.post1112109313858778137..comments2024-03-28T06:30:36.587-07:00Comments on Code like a boss: Java Concurrency Part 4Anonymoushttp://www.blogger.com/profile/08290643904561387397noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-4213799477897003979.post-65918256799160944852013-06-06T14:53:29.084-07:002013-06-06T14:53:29.084-07:00Glad to help you ;) Glad to help you ;) Anonymoushttps://www.blogger.com/profile/08290643904561387397noreply@blogger.comtag:blogger.com,1999:blog-4213799477897003979.post-61509652991159489652013-06-06T14:46:21.117-07:002013-06-06T14:46:21.117-07:00You are right about the String, good to know that....You are right about the String, good to know that.<br />ThanksAnonymoushttps://www.blogger.com/profile/05677407543547214668noreply@blogger.comtag:blogger.com,1999:blog-4213799477897003979.post-65531490997744261132013-06-05T14:45:20.777-07:002013-06-05T14:45:20.777-07:00The consumer starts reading and if no message is a...The consumer starts reading and if no message is available then it should wait, but if the "empty" flag of the MessageBox class is not initialized or set to false, which is the deafult value for a boolean type then it will read an empty message. <br /><br />Sometimes the little details provoke big bugs!Anonymoushttps://www.blogger.com/profile/08290643904561387397noreply@blogger.comtag:blogger.com,1999:blog-4213799477897003979.post-19602337615857636822013-06-05T14:36:18.459-07:002013-06-05T14:36:18.459-07:00Well you should know that strings behave different...Well you should know that strings behave differently since they reside in a pool, and the JVM doesn't create two instances of the same string unless you use a reference to it. <br /><br />So if you use the same string then you are using one object, go on and create an empty class and use it as resource and try it again, it should work! ;)<br /><br />And keep it in mind that the code is forcing the deadlock, that's why the sleep() sentence is in the code, and deadlocks happen randomly.<br />Anonymoushttps://www.blogger.com/profile/08290643904561387397noreply@blogger.comtag:blogger.com,1999:blog-4213799477897003979.post-3900184600120806302013-06-05T13:26:29.741-07:002013-06-05T13:26:29.741-07:00Even the first example with the Deadlock class has...Even the first example with the Deadlock class has issues inside.<br />I've created this class with String as a replacement class instead of the Resource placeholder and as a result both threads ended without deadlock occurring.Anonymoushttps://www.blogger.com/profile/05677407543547214668noreply@blogger.comtag:blogger.com,1999:blog-4213799477897003979.post-19186639103949856942013-06-05T13:18:01.594-07:002013-06-05T13:18:01.594-07:00The code for MessageBox is not correct.
When you p...The code for MessageBox is not correct.<br />When you print what both consumer and producer do, you can see that consumer consumes an item which is not even produced yet, so I'm guessing the synchronization along with conditions is not correctAnonymoushttps://www.blogger.com/profile/05677407543547214668noreply@blogger.com