Skip to content

Commit 90b5b24

Browse files
author
SendaoYan
committed
8351601: [JMH] test UnixSocketChannelReadWrite failed for 2 threads config
Backport-of: bc224e2631838bdb0595d4986ac6176e2fe47cb5
1 parent d2dad32 commit 90b5b24

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

test/micro/org/openjdk/bench/java/net/UnixSocketChannelReadWrite.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,7 +31,6 @@
3131
import java.nio.channels.SocketChannel;
3232
import java.nio.file.*;
3333
import java.util.concurrent.TimeUnit;
34-
import java.util.concurrent.atomic.AtomicInteger;
3534

3635
import org.openjdk.jmh.annotations.*;
3736

@@ -49,22 +48,10 @@ public class UnixSocketChannelReadWrite {
4948
private ReadThread rt;
5049
private ByteBuffer bb = ByteBuffer.allocate(1);
5150

52-
private static volatile String tempDir;
53-
private static final AtomicInteger count = new AtomicInteger(0);
5451
private volatile Path socket;
5552

56-
static {
57-
try {
58-
Path p = Files.createTempDirectory("readWriteTest");
59-
tempDir = p.toString();
60-
} catch (IOException e) {
61-
tempDir = null;
62-
}
63-
}
64-
6553
private ServerSocketChannel getServerSocketChannel() throws IOException {
66-
int next = count.incrementAndGet();
67-
socket = Paths.get(tempDir, Integer.toString(next));
54+
socket = Files.createTempDirectory(UnixSocketChannelReadWrite.class.getSimpleName()).resolve("sock");
6855
UnixDomainSocketAddress addr = UnixDomainSocketAddress.of(socket);
6956
ServerSocketChannel c = ServerSocketChannel.open(StandardProtocolFamily.UNIX);
7057
c.bind(addr);
@@ -90,7 +77,7 @@ public void afterRun() throws IOException, InterruptedException {
9077
s2.close();
9178
ssc.close();
9279
Files.delete(socket);
93-
Files.delete(Path.of(tempDir));
80+
Files.delete(socket.getParent());
9481
rt.join();
9582
}
9683

0 commit comments

Comments
 (0)