Skip to content

Commit d723597

Browse files
author
Brian Burkhalter
committed
8345432: (ch, fs) Replace anonymous Thread with InnocuousThread
Reviewed-by: alanb
1 parent 9c393a2 commit d723597

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

src/java.base/share/classes/sun/nio/ch/ThreadPool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ int poolSize() {
7070

7171
static ThreadFactory defaultThreadFactory() {
7272
return (Runnable r) -> {
73-
Thread t = new Thread(r);
73+
Thread t = InnocuousThread.newThread(r);
7474
t.setDaemon(true);
7575
return t;
7676
};

src/java.base/share/classes/sun/nio/fs/AbstractPoller.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525

2626
package sun.nio.fs;
2727

28-
import java.nio.file.*;
2928
import java.io.IOException;
29+
import java.nio.file.*;
3030
import java.util.*;
31+
import jdk.internal.misc.InnocuousThread;
3132

3233
/**
3334
* Base implementation of background poller thread used in watch service
@@ -53,11 +54,7 @@ protected AbstractPoller() {
5354
* Starts the poller thread
5455
*/
5556
public void start() {
56-
Thread thr = new Thread(null,
57-
this,
58-
"FileSystemWatchService",
59-
0,
60-
false);
57+
Thread thr = InnocuousThread.newThread("FileSystemWatchService", this);
6158
thr.setDaemon(true);
6259
thr.start();
6360
}

src/java.base/share/classes/sun/nio/fs/Cancellable.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2024, 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
@@ -25,14 +25,15 @@
2525

2626
package sun.nio.fs;
2727

28-
import jdk.internal.misc.Unsafe;
2928
import java.util.concurrent.ExecutionException;
29+
import jdk.internal.misc.InnocuousThread;
30+
import jdk.internal.misc.Unsafe;
3031

3132
/**
3233
* Base implementation of a task (typically native) that polls a memory location
3334
* during execution so that it may be aborted/cancelled before completion. The
34-
* task is executed by invoking the {@link runInterruptibly} method defined
35-
* here and cancelled by invoking Thread.interrupt.
35+
* task is executed by invoking the {@linkplain #runInterruptibly} method
36+
* defined here and cancelled by invoking Thread.interrupt.
3637
*/
3738

3839
abstract class Cancellable implements Runnable {
@@ -117,7 +118,7 @@ public final void run() {
117118
* thread by writing into the memory location that it polls cooperatively.
118119
*/
119120
static void runInterruptibly(Cancellable task) throws ExecutionException {
120-
Thread t = new Thread(null, task, "NIO-Task", 0, false);
121+
Thread t = InnocuousThread.newThread("CancellableOp", task);
121122
t.start();
122123
boolean cancelledByInterrupt = false;
123124
while (t.isAlive()) {

src/java.base/share/classes/sun/nio/fs/PollingWatchService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.util.concurrent.ScheduledFuture;
4848
import java.util.concurrent.ThreadFactory;
4949
import java.util.concurrent.TimeUnit;
50+
import jdk.internal.misc.InnocuousThread;
5051
import static java.nio.file.LinkOption.NOFOLLOW_LINKS;
5152

5253
/**
@@ -73,7 +74,7 @@ class PollingWatchService
7374
.newSingleThreadScheduledExecutor(new ThreadFactory() {
7475
@Override
7576
public Thread newThread(Runnable r) {
76-
Thread t = new Thread(null, r, "FileSystemWatcher", 0, false);
77+
Thread t = InnocuousThread.newThread("FileSystemWatcher", r);
7778
t.setDaemon(true);
7879
return t;
7980
}});

src/java.base/windows/classes/sun/nio/ch/PipeImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void init() throws IOException {
7878
connector.run();
7979
if (ioe instanceof ClosedByInterruptException) {
8080
ioe = null;
81-
Thread connThread = new Thread(connector) {
81+
Thread connThread = new Thread(connector, "LoopbackConnector") {
8282
@Override
8383
public void interrupt() {}
8484
};

0 commit comments

Comments
 (0)