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
3131import java .nio .channels .SocketChannel ;
3232import java .nio .file .*;
3333import java .util .concurrent .TimeUnit ;
34- import java .util .concurrent .atomic .AtomicInteger ;
3534
3635import 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