Hi, Chris.
What is the reason to use assertion? If the problem is not theoretical,
then probably OOM(or something like that) will be better?
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.