Wednesday 15 January 2014

java - Synchronized Circular Queue -


I am implementing a very simple synchronized circular line , as my Is it possible to deadlock ! But I do not believe that,

In fact when a thread wants dequeue (polling) if the queue is empty, then it will have to wait until another thread, anu, and vice versa if the queue is full, / P>

I'm not very good at detecting deadlock prone codes, do you think this is likely to be a deadlock? Import java.util.ArrayList; Square circular quiz & lt; T & gt; {ArrayList & lt; T & gt; Q; Integer, back, shape; Public circular qu (int size) {q = new arreelist & lt; T & gt; (); For (int i = 0; i

There are several problems with your implementation:

  • Notify () calls should come from inside the synchronize block
  • Your implementation creates "speakers" - one type To recover the Java memory leak, when objects should be collected from long periods of time, set the element returning from poll () to null .
  • You will see ArrayList & lt; No need to use T & gt; and fill it with null s; The plain array of the object will suffice, you will need to add castings, but it is happening with or without ArrayList so that you can take it to your code.
  • This last point stops progressing permanently from malicious users of your queue by not synchronizing them on the queue object, not releasing the lock.

No comments:

Post a Comment