RFR [9] Remove sun.misc.Queue and replace usages with standard Collections
Sergey Bylokhov
Sergey.Bylokhov at oracle.com
Wed Dec 16 22:48:03 UTC 2015
>>> What is the reason to use assertion? If the problem is not theoretical,
>
> That was tricky to spot :-) nearly missed it.
> Since the queue is not "capacity-restricted" i think add(E) is the more appropriate choice.
+1 I think so.
>
> —
>
> I suspect this use of queues in AppletPanel could be cleaned up given the usages of with synchronised blocks (and the sun.misc.Queue style is probably a hangover from the java.util.Vector days). Anyway, that’s for another day if the AWT devs want to take that on :-)
>
> Paul.
>
>>
>>> 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.
>>
>
--
Best regards, Sergey.
More information about the core-libs-dev
mailing list