< prev index next >

src/java.base/share/classes/sun/nio/ch/Poller.java

Print this page

711             masterPoller.shutdown();
712         }
713 
714         private Poller writePoller(int fdVal) {
715             int index = provider().fdValToIndex(fdVal, writePollers.length);
716             return writePollers[index];
717         }
718 
719         /**
720          * Starts a read sub-poller in a virtual thread.
721          */
722         private Poller startReadPoller() throws IOException {
723             assert Thread.currentThread().isVirtual() && ContinuationSupport.isSupported();
724 
725             // create read sub-poller
726             Poller readPoller = provider().readPoller(true);
727             readPollers.add(readPoller);
728 
729             // start virtual thread to execute sub-polling loop
730             Thread carrier = JLA.currentCarrierThread();
731             Thread.ofVirtual()
732                     .inheritInheritableThreadLocals(false)
733                     .name(carrier.getName() + "-Read-Poller")
734                     .uncaughtExceptionHandler((_, e) -> e.printStackTrace())
735                     .start(() -> subPollerLoop(readPoller));



736             return readPoller;
737         }
738 
739         /**
740          * Returns the read poller for the current carrier, starting it if required.
741          */
742         private Poller readPoller() throws IOException {
743             assert Thread.currentThread().isVirtual() && ContinuationSupport.isSupported();
744             Continuation.pin();
745             try {
746                 CarrierPoller carrierPoller = CARRIER_POLLER.get();
747                 if (carrierPoller != null) {
748                     return carrierPoller.readPoller();
749                 } else {
750                     // first poll on this carrier will start poller
751                     Poller readPoller = startReadPoller();
752                     CARRIER_POLLER.set(new CarrierPoller(this, readPoller));
753                     return readPoller;
754                 }
755             } finally {

711             masterPoller.shutdown();
712         }
713 
714         private Poller writePoller(int fdVal) {
715             int index = provider().fdValToIndex(fdVal, writePollers.length);
716             return writePollers[index];
717         }
718 
719         /**
720          * Starts a read sub-poller in a virtual thread.
721          */
722         private Poller startReadPoller() throws IOException {
723             assert Thread.currentThread().isVirtual() && ContinuationSupport.isSupported();
724 
725             // create read sub-poller
726             Poller readPoller = provider().readPoller(true);
727             readPollers.add(readPoller);
728 
729             // start virtual thread to execute sub-polling loop
730             Thread carrier = JLA.currentCarrierThread();
731             Thread.Builder.OfVirtual builder = Thread.ofVirtual()
732                     .inheritInheritableThreadLocals(false)
733                     .name(carrier.getName() + "-Read-Poller")
734                     .uncaughtExceptionHandler((_, e) -> e.printStackTrace());
735             Thread thread = JLA.defaultVirtualThreadScheduler()
736                     .newThread(builder, carrier, () -> subPollerLoop(readPoller))
737                     .thread();
738             thread.start();
739             return readPoller;
740         }
741 
742         /**
743          * Returns the read poller for the current carrier, starting it if required.
744          */
745         private Poller readPoller() throws IOException {
746             assert Thread.currentThread().isVirtual() && ContinuationSupport.isSupported();
747             Continuation.pin();
748             try {
749                 CarrierPoller carrierPoller = CARRIER_POLLER.get();
750                 if (carrierPoller != null) {
751                     return carrierPoller.readPoller();
752                 } else {
753                     // first poll on this carrier will start poller
754                     Poller readPoller = startReadPoller();
755                     CARRIER_POLLER.set(new CarrierPoller(this, readPoller));
756                     return readPoller;
757                 }
758             } finally {
< prev index next >