< prev index next > src/java.base/share/classes/sun/nio/ch/Poller.java
Print this page
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.locks.LockSupport;
import java.util.function.BooleanSupplier;
import jdk.internal.misc.InnocuousThread;
+ import jdk.internal.vm.annotation.Stable;
/**
* Polls file descriptors. Virtual threads invoke the poll method to park
* until a given file descriptor is ready for I/O.
*/
} catch (IOException ioe) {
throw new ExceptionInInitializerError(ioe);
}
}
+ // the poller or sub-poller thread
+ private @Stable Thread owner;
+
// maps file descriptors to parked Thread
private final Map<Integer, Thread> map = new ConcurrentHashMap<>();
/**
* Poller mode.
/**
* Master polling loop. The {@link #polled(int)} method is invoked for each file
* descriptor that is polled.
*/
private void pollerLoop() {
+ owner = Thread.currentThread();
try {
for (;;) {
poll(-1);
}
} catch (Exception e) {
* again when there are no more events. The sub-poller yields after each poll to help
* with fairness and to avoid re-registering with the master poller where possible.
*/
private void subPollerLoop(Poller masterPoller) {
assert Thread.currentThread().isVirtual();
+ owner = Thread.currentThread();
try {
int polled = 0;
for (;;) {
if (polled == 0) {
masterPoller.poll(fdVal(), 0, () -> true); // park
return map.size();
}
@Override
public String toString() {
- return Objects.toIdentityString(this) + " [registered = " + registered() + "]";
+ return String.format("%s [registered = %d, owner = %s]",
+ Objects.toIdentityString(this), registered(), owner);
}
/**
* The Pollers used for read and write events.
*/
} catch (Exception e) {
throw new InternalError(e);
}
}
}
+
+ /**
+ * Return the master poller or null if there is no master poller.
+ */
+ public static Poller masterPoller() {
+ return POLLERS.masterPoller();
+ }
+
+ /**
+ * Return the list of read pollers.
+ */
+ public static List<Poller> readPollers() {
+ return POLLERS.readPollers();
+ }
+
+ /**
+ * Return the list of write pollers.
+ */
+ public static List<Poller> writePollers() {
+ return POLLERS.writePollers();
+ }
}
< prev index next >