Skip to content

Commit 922b458

Browse files
author
duke
committed
Backport 03105fc92505e9e367354e763b99cbe02bf473d6
1 parent 13e1932 commit 922b458

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

@@ -52,22 +51,10 @@ public class UnixSocketChannelReadWrite {
5251
private ReadThread rt;
5352
private ByteBuffer bb = ByteBuffer.allocate(1);
5453

55-
private static volatile String tempDir;
56-
private static final AtomicInteger count = new AtomicInteger(0);
5754
private volatile Path socket;
5855

59-
static {
60-
try {
61-
Path p = Files.createTempDirectory("readWriteTest");
62-
tempDir = p.toString();
63-
} catch (IOException e) {
64-
tempDir = null;
65-
}
66-
}
67-
6856
private ServerSocketChannel getServerSocketChannel() throws IOException {
69-
int next = count.incrementAndGet();
70-
socket = Paths.get(tempDir, Integer.toString(next));
57+
socket = Files.createTempDirectory(UnixSocketChannelReadWrite.class.getSimpleName()).resolve("sock");
7158
UnixDomainSocketAddress addr = UnixDomainSocketAddress.of(socket);
7259
ServerSocketChannel c = ServerSocketChannel.open(StandardProtocolFamily.UNIX);
7360
c.bind(addr);
@@ -93,7 +80,7 @@ public void afterRun() throws IOException, InterruptedException {
9380
s2.close();
9481
ssc.close();
9582
Files.delete(socket);
96-
Files.delete(Path.of(tempDir));
83+
Files.delete(socket.getParent());
9784
rt.join();
9885
}
9986

0 commit comments

Comments
 (0)