Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/nio/channels/Selector/LotsOfChannels.java
41153 views
1
/*
2
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
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 4503092 8024883
26
* @summary Tests that Windows Selector can use more than 63 channels
27
* @run main LotsOfChannels
28
* @run main/othervm -Dsun.nio.ch.maxUpdateArraySize=64 LotsOfChannels
29
* @author kladko
30
*/
31
32
/* @test
33
* @requires (os.family == "windows")
34
* @run main/othervm -Djava.nio.channels.spi.SelectorProvider=sun.nio.ch.WindowsSelectorProvider LotsOfChannels
35
*/
36
37
import java.net.*;
38
import java.io.*;
39
import java.nio.*;
40
import java.nio.channels.*;
41
42
public class LotsOfChannels {
43
44
private final static int PIPES_COUNT = 256;
45
private final static int BUF_SIZE = 8192;
46
private final static int LOOPS = 10;
47
48
public static void main(String[] argv) throws Exception {
49
Pipe[] pipes = new Pipe[PIPES_COUNT];
50
Pipe pipe = Pipe.open();
51
Pipe.SinkChannel sink = pipe.sink();
52
Pipe.SourceChannel source = pipe.source();
53
Selector sel = Selector.open();
54
source.configureBlocking(false);
55
source.register(sel, SelectionKey.OP_READ);
56
57
for (int i = 0; i< PIPES_COUNT; i++ ) {
58
pipes[i]= Pipe.open();
59
Pipe.SourceChannel sc = pipes[i].source();
60
sc.configureBlocking(false);
61
sc.register(sel, SelectionKey.OP_READ);
62
Pipe.SinkChannel sc2 = pipes[i].sink();
63
sc2.configureBlocking(false);
64
sc2.register(sel, SelectionKey.OP_WRITE);
65
}
66
67
for (int i = 0 ; i < LOOPS; i++ ) {
68
sink.write(ByteBuffer.allocate(BUF_SIZE));
69
int x = sel.selectNow();
70
sel.selectedKeys().clear();
71
source.read(ByteBuffer.allocate(BUF_SIZE));
72
}
73
74
for (int i = 0; i < PIPES_COUNT; i++ ) {
75
pipes[i].sink().close();
76
pipes[i].source().close();
77
}
78
pipe.sink().close();
79
pipe.source().close();
80
sel.close();
81
}
82
}
83
84