1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
31
31
import java .nio .channels .SocketChannel ;
32
32
import java .nio .file .*;
33
33
import java .util .concurrent .TimeUnit ;
34
- import java .util .concurrent .atomic .AtomicInteger ;
35
34
36
35
import org .openjdk .jmh .annotations .*;
37
36
@@ -49,22 +48,10 @@ public class UnixSocketChannelReadWrite {
49
48
private ReadThread rt ;
50
49
private ByteBuffer bb = ByteBuffer .allocate (1 );
51
50
52
- private static volatile String tempDir ;
53
- private static final AtomicInteger count = new AtomicInteger (0 );
54
51
private volatile Path socket ;
55
52
56
- static {
57
- try {
58
- Path p = Files .createTempDirectory ("readWriteTest" );
59
- tempDir = p .toString ();
60
- } catch (IOException e ) {
61
- tempDir = null ;
62
- }
63
- }
64
-
65
53
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" );
68
55
UnixDomainSocketAddress addr = UnixDomainSocketAddress .of (socket );
69
56
ServerSocketChannel c = ServerSocketChannel .open (StandardProtocolFamily .UNIX );
70
57
c .bind (addr );
@@ -90,7 +77,7 @@ public void afterRun() throws IOException, InterruptedException {
90
77
s2 .close ();
91
78
ssc .close ();
92
79
Files .delete (socket );
93
- Files .delete (Path . of ( tempDir ));
80
+ Files .delete (socket . getParent ( ));
94
81
rt .join ();
95
82
}
96
83
0 commit comments