Thanks for looking at this Sergey.

> On 13 Dec 2015, at 11:16, Sergey Bylokhov <sergey.bylok...@oracle.com> wrote:
> 
> Hi, Chris.
> What is the reason to use assertion? If the problem is not theoretical,

Hmm… The queue is “unbounded”, but actually has a capacity of
Integer.MAX_VALUE. I suspect that this will never be reached, but
I accept your comment.  Maybe add(E) is more appropriate? add()
either succeeds, or fails with IllegalStateException.

> then probably OOM(or something like that) will be better?

I don’t think OOM is quite right. Maybe ISE, as above is better?

-Chris.


> On 11/12/15 20:22, Chris Hegarty wrote:
>> More technical debt in sun.misc…
>> 
>> Java SE has had support for Queues in Collections for many major releases,
>> sun.misc.Queue seems to predate that. I cannot find any usages outside of the
>> JDK, and just one in the JDK, AppletPanel. LinkedBlockingQueue appears to
>> provide the necessary minimum functionality required by AppletPanel, FIFO
>> blocking operations.
>> 
>> The changes are quite small so I just included the diffs inline.
>> 
>> Note: we could use either add(E) or offer(E) below, I don’t have a strong 
>> opinion
>> either way.
>> 
>> $ hg rm src/java.base/share/classes/sun/misc/Queue.java
>> 
>> diff --git a/src/java.desktop/share/classes/sun/applet/AppletPanel.java 
>> b/src/java.desktop/share/classes/sun/applet/AppletPanel.java
>> --- a/src/java.desktop/share/classes/sun/applet/AppletPanel.java
>> +++ b/src/java.desktop/share/classes/sun/applet/AppletPanel.java
>> @@ -38,6 +38,7 @@
>>  import java.security.*;
>>  import java.util.*;
>>  import java.util.Locale;
>> +import java.util.concurrent.LinkedBlockingQueue;
>>  import sun.awt.AWTAccessor;
>>  import sun.awt.AppContext;
>>  import sun.awt.EmbeddedFrame;
>> @@ -45,7 +46,6 @@
>>  import sun.misc.ManagedLocalsThread;
>>  import sun.misc.MessageUtils;
>>  import sun.misc.PerformanceLogger;
>> -import sun.misc.Queue;
>>  import sun.security.util.SecurityConstants;
>> 
>>  /**
>> @@ -247,8 +247,7 @@
>>      /**
>>       * AppletEvent Queue
>>       */
>> -    private Queue<Integer> queue = null;
>> -
>> +    private LinkedBlockingQueue<Integer> queue = null;
>> 
>>      public synchronized void addAppletListener(AppletListener l) {
>>          listeners = AppletEventMulticaster.add(listeners, l);
>> @@ -276,10 +275,10 @@
>>          synchronized(this) {
>>              if (queue == null) {
>>                  //System.out.println("SEND0= " + id);
>> -                queue = new Queue<>();
>> +                queue = new LinkedBlockingQueue<>();
>>              }
>> -            Integer eventId = Integer.valueOf(id);
>> -            queue.enqueue(eventId);
>> +            boolean inserted = queue.offer(id);
>> +            assert inserted;
>>              notifyAll();
>>          }
>>          if (id == APPLET_QUIT) {
>> @@ -303,8 +302,8 @@
>>          while (queue == null || queue.isEmpty()) {
>>              wait();
>>          }
>> -        Integer eventId = queue.dequeue();
>> -        return new AppletEvent(this, eventId.intValue(), null);
>> +        int eventId = queue.take();
>> +        return new AppletEvent(this, eventId, null);
>>      }
>> 
>>      boolean emptyEventQueue() {
>> 
>> -Chris.
>> 
> 
> 
> -- 
> Best regards, Sergey.

Reply via email to