11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* @test 25 * @bug 8201315 26 * @summary Test that channels can be registered, interest ops can changed, 27 * and keys cancelled while a selection operation is in progress. 28 */ 29 30 import java.io.IOException; 31 import java.nio.channels.Pipe; 32 import java.nio.channels.SelectionKey; 33 import java.nio.channels.Selector; 34 import java.util.concurrent.Callable; 35 import java.util.concurrent.ExecutorService; 36 import java.util.concurrent.Executors; 37 import java.util.concurrent.Future; 38 import java.util.concurrent.Phaser; 39 40 public class RegisterDuringSelect { 41 42 static Callable<Void> selectLoop(Selector sel, Phaser barrier) { 43 return new Callable<Void>() { 44 @Override 45 public Void call() throws IOException { 46 for (;;) { 47 sel.select(); 48 if (sel.isOpen()) { 49 barrier.arriveAndAwaitAdvance(); 50 } else { 51 // closed 52 return null; 53 } 54 } 55 } 56 }; 57 } 58 /** 59 * Invoke register, interestOps, and cancel concurrently with a thread 60 * doing a selection operation 61 */ 62 public static void main(String args[]) throws Exception { 63 Future<Void> result; 64 65 ExecutorService pool = Executors.newFixedThreadPool(1); 66 try (Selector sel = Selector.open()) { 67 Phaser barrier = new Phaser(2); 68 69 // submit task to do the select loop | 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* @test 25 * @bug 8201315 26 * @summary Test that channels can be registered, interest ops can changed, 27 * and keys cancelled while a selection operation is in progress. 28 */ 29 30 import java.io.IOException; 31 import java.nio.channels.ClosedSelectorException; 32 import java.nio.channels.Pipe; 33 import java.nio.channels.SelectionKey; 34 import java.nio.channels.Selector; 35 import java.util.concurrent.Callable; 36 import java.util.concurrent.ExecutorService; 37 import java.util.concurrent.Executors; 38 import java.util.concurrent.Future; 39 import java.util.concurrent.Phaser; 40 41 public class RegisterDuringSelect { 42 43 static Callable<Void> selectLoop(Selector sel, Phaser barrier) { 44 return new Callable<Void>() { 45 @Override 46 public Void call() throws IOException { 47 for (;;) { 48 try { 49 sel.select(); 50 } catch (ClosedSelectorException ignore) { 51 return null; 52 } 53 if (sel.isOpen()) { 54 barrier.arriveAndAwaitAdvance(); 55 System.out.println("phaser in executor ..."); 56 } else { 57 // closed 58 return null; 59 } 60 } 61 } 62 }; 63 } 64 /** 65 * Invoke register, interestOps, and cancel concurrently with a thread 66 * doing a selection operation 67 */ 68 public static void main(String args[]) throws Exception { 69 Future<Void> result; 70 71 ExecutorService pool = Executors.newFixedThreadPool(1); 72 try (Selector sel = Selector.open()) { 73 Phaser barrier = new Phaser(2); 74 75 // submit task to do the select loop |