Skip to content

Commit 0598c6b

Browse files
committed
Merge remote-tracking branch 'origin/develop' into develop
2 parents bde620b + e1df39d commit 0598c6b

7 files changed

Lines changed: 71 additions & 41 deletions

File tree

affinity-test/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</parent>
2727

2828
<artifactId>affinity-test</artifactId>
29-
<version>3.21ea81-SNAPSHOT</version>
29+
<version>3.21ea82-SNAPSHOT</version>
3030
<packaging>bundle</packaging>
3131

3232
<name>OpenHFT/Java-Thread-Affinity/affinity-test</name>

affinity/pom.xml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@
1515
~ limitations under the License.
1616
-->
1717

18-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
18+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1920
<modelVersion>4.0.0</modelVersion>
2021

2122
<parent>
2223
<groupId>net.openhft</groupId>
2324
<artifactId>java-parent-pom</artifactId>
2425
<version>1.1.26</version>
25-
<relativePath />
26+
<relativePath/>
2627
</parent>
2728

2829
<artifactId>affinity</artifactId>
29-
<version>3.21ea81-SNAPSHOT</version>
30+
<version>3.21ea82-SNAPSHOT</version>
3031
<packaging>bundle</packaging>
3132

3233
<name>OpenHFT/Java-Thread-Affinity/affinity</name>
@@ -126,6 +127,35 @@
126127
</plugins>
127128
</build>
128129
</profile>
130+
<profile>
131+
<id>sonar</id>
132+
<build>
133+
<plugins>
134+
<plugin>
135+
<groupId>org.sonarsource.scanner.maven</groupId>
136+
<artifactId>sonar-maven-plugin</artifactId>
137+
</plugin>
138+
<plugin>
139+
<groupId>org.jacoco</groupId>
140+
<artifactId>jacoco-maven-plugin</artifactId>
141+
<executions>
142+
<execution>
143+
<goals>
144+
<goal>prepare-agent</goal>
145+
</goals>
146+
</execution>
147+
<execution>
148+
<id>report</id>
149+
<phase>prepare-package</phase>
150+
<goals>
151+
<goal>report</goal>
152+
</goals>
153+
</execution>
154+
</executions>
155+
</plugin>
156+
</plugins>
157+
</build>
158+
</profile>
129159
</profiles>
130160

131161
<build>
@@ -224,7 +254,7 @@
224254
<connection>scm:git:[email protected]:OpenHFT/Java-Thread-Affinity.git</connection>
225255
<developerConnection>scm:git:[email protected]:OpenHFT/Java-Thread-Affinity.git
226256
</developerConnection>
227-
<tag>ea</tag>
257+
<tag>ea</tag>
228258
</scm>
229259

230260
</project>

affinity/src/main/java/net/openhft/affinity/BootClassPath.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ private static Set<String> findResources(final Path path, final Logger logger) {
6767

6868
private static Set<String> findResourcesInJar(final Path path, final Logger logger) {
6969
final Set<String> jarResources = new HashSet<>();
70-
try {
71-
final JarFile jarFile = new JarFile(path.toFile());
70+
try (final JarFile jarFile = new JarFile(path.toFile())) {
7271
final Enumeration<JarEntry> entries = jarFile.entries();
7372
while (entries.hasMoreElements()) {
7473
final JarEntry jarEntry = entries.nextElement();

affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@ public class MicroJitterSampler {
3939
private final int[] count = new int[DELAY.length];
4040
private long totalTime = 0;
4141

42-
private static void pause() throws InterruptedException
43-
{
44-
if(BUSYWAIT) {
42+
private static void pause() throws InterruptedException {
43+
if (BUSYWAIT) {
4544
long now = System.nanoTime();
46-
while(System.nanoTime() - now < 1_000_000);
45+
while (System.nanoTime() - now < 1_000_000) ;
4746
} else {
4847
Thread.sleep(1);
4948
}
5049

5150
}
51+
5252
public static void main(String... ignored) throws InterruptedException {
5353
MicroJitterSampler sampler = new MicroJitterSampler();
5454

55-
Thread t = new Thread( sampler::run );
55+
Thread t = new Thread(sampler::run);
5656
t.start();
5757
t.join();
5858
}
@@ -71,7 +71,7 @@ private void once() throws InterruptedException {
7171
}
7272

7373
public void run() {
74-
if(CPU != -1)
74+
if (CPU != -1)
7575
Affinity.setAffinity(CPU);
7676

7777
try {
@@ -80,7 +80,7 @@ public void run() {
8080
while (!Thread.currentThread().isInterrupted()) {
8181
once();
8282

83-
if(first) {
83+
if (first) {
8484
reset();
8585
first = false;
8686
System.out.println("Warmup complete. Running jitter tests...");
@@ -89,7 +89,8 @@ public void run() {
8989

9090
print(System.out);
9191
}
92-
} catch(InterruptedException e) {
92+
} catch (InterruptedException e) {
93+
Thread.currentThread().interrupt();
9394
}
9495
}
9596

@@ -101,7 +102,7 @@ private static String asString(long timeNS) {
101102
}
102103

103104
void reset() {
104-
for(int i=0; i<DELAY.length; ++i)
105+
for (int i = 0; i < DELAY.length; ++i)
105106
count[i] = 0;
106107
totalTime = 0;
107108
}

affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
public class FileLockBasedLockChecker implements LockChecker {
2727

2828
private static final int MAX_LOCK_RETRIES = 5;
29-
private static final SimpleDateFormat df = new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z");
29+
private static final ThreadLocal<SimpleDateFormat> dfTL = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z"));
3030
private static final FileAttribute<Set<PosixFilePermission>> LOCK_FILE_ATTRIBUTES = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-rw-rw-"));
3131
private static final Set<OpenOption> LOCK_FILE_OPEN_OPTIONS = new HashSet<>(Arrays.asList(READ, WRITE, CREATE, SYNC));
3232
private static final Logger LOGGER = LoggerFactory.getLogger(FileLockBasedLockChecker.class);
@@ -54,7 +54,9 @@ public synchronized boolean isLockFree(int id) {
5454
// if we can acquire a shared lock, nobody has an exclusive lock
5555
try (final FileLock fileLock = channel.tryLock(0, Long.MAX_VALUE, true)) {
5656
if (fileLock != null && fileLock.isValid()) {
57-
lockFile.delete(); // clean up the orphaned lock file
57+
if (!lockFile.delete()) { // try and clean up the orphaned lock file
58+
LOGGER.debug("Couldn't delete orphaned lock file " + lockFile);
59+
}
5860
return true;
5961
} else {
6062
// another process has an exclusive lock
@@ -102,7 +104,7 @@ public synchronized boolean obtainLock(int id, String metaInfo) throws IOExcepti
102104
*/
103105
private LockReference tryAcquireLockOnFile(int id, String metaInfo) throws IOException, ConcurrentLockFileDeletionException {
104106
final File lockFile = toFile(id);
105-
final FileChannel fileChannel = FileChannel.open(lockFile.toPath(), LOCK_FILE_OPEN_OPTIONS, LOCK_FILE_ATTRIBUTES);
107+
final FileChannel fileChannel = FileChannel.open(lockFile.toPath(), LOCK_FILE_OPEN_OPTIONS, LOCK_FILE_ATTRIBUTES); // NOSONAR
106108
final FileLock fileLock = fileChannel.tryLock(0, Long.MAX_VALUE, false);
107109
if (fileLock == null) {
108110
// someone else has a lock (exclusive or shared), fail to acquire
@@ -122,7 +124,7 @@ private LockReference tryAcquireLockOnFile(int id, String metaInfo) throws IOExc
122124
}
123125

124126
private void writeMetaInfoToFile(FileChannel fc, String metaInfo) throws IOException {
125-
byte[] content = String.format("%s%n%s", metaInfo, df.format(new Date())).getBytes();
127+
byte[] content = String.format("%s%n%s", metaInfo, dfTL.get().format(new Date())).getBytes();
126128
ByteBuffer buffer = ByteBuffer.wrap(content);
127129
while (buffer.hasRemaining()) {
128130
fc.write(buffer);

affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
* @author Tom Shercliff
1111
*/
1212
public class AffinityTestMain {
13-
private static final SimpleDateFormat df = new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z");
1413

1514
public static void main(String[] args) {
1615

@@ -28,21 +27,19 @@ public static void main(String[] args) {
2827

2928
private static void acquireAndDoWork() {
3029

31-
Thread t = new Thread(new Runnable() {
32-
@Override
33-
public void run() {
34-
try (AffinityLock al = Affinity.acquireLock()) {
35-
String threadName = Thread.currentThread().getName();
36-
System.out.println("Thread (" + threadName + ") locked onto cpu " + al.cpuId());
37-
38-
while (true) {
39-
System.out.println(df.format(new Date()) + " - Thread (" + threadName + ") doing work on cpu " + al.cpuId() + ". IsAllocated = " + al.isAllocated() + ", isBound = " + al.isBound() + ". " + al.toString());
40-
41-
try {
42-
Thread.sleep(10000L);
43-
} catch (InterruptedException e) {
44-
//nothing
45-
}
30+
Thread t = new Thread(() -> {
31+
final SimpleDateFormat df = new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z");
32+
try (AffinityLock al = Affinity.acquireLock()) {
33+
String threadName = Thread.currentThread().getName();
34+
System.out.println("Thread (" + threadName + ") locked onto cpu " + al.cpuId());
35+
36+
while (true) {
37+
System.out.println(df.format(new Date()) + " - Thread (" + threadName + ") doing work on cpu " + al.cpuId() + ". IsAllocated = " + al.isAllocated() + ", isBound = " + al.isBound() + ". " + al.toString());
38+
39+
try {
40+
Thread.sleep(10000L);
41+
} catch (InterruptedException e) {
42+
//nothing
4643
}
4744
}
4845
}

pom.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@
1515
~ limitations under the License.
1616
-->
1717

18-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
18+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1920
<modelVersion>4.0.0</modelVersion>
2021

2122
<parent>
2223
<groupId>net.openhft</groupId>
2324
<artifactId>root-parent-pom</artifactId>
24-
<version>1.2.1</version>
25-
<relativePath />
25+
<version>1.2.13</version>
26+
<relativePath/>
2627
</parent>
2728

2829
<artifactId>Java-Thread-Affinity</artifactId>
29-
<version>3.21ea81-SNAPSHOT</version>
30+
<version>3.21ea82-SNAPSHOT</version>
3031
<packaging>pom</packaging>
3132

3233
<name>OpenHFT/Java-Thread-Affinity Parent</name>
@@ -42,7 +43,7 @@
4243
<connection>scm:git:[email protected]:OpenHFT/Java-Thread-Affinity.git</connection>
4344
<developerConnection>scm:git:[email protected]:OpenHFT/Java-Thread-Affinity.git
4445
</developerConnection>
45-
<tag>ea</tag>
46+
<tag>ea</tag>
4647
</scm>
4748

4849
</project>

0 commit comments

Comments
 (0)