Skip to content

Commit 27521ef

Browse files
authored
Centralise thread name logic (#8513)
1 parent aac6c70 commit 27521ef

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

okhttp/src/main/kotlin/okhttp3/internal/concurrent/TaskRunner.kt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import okhttp3.internal.connection.Locks.newLockCondition
3030
import okhttp3.internal.connection.Locks.withLock
3131
import okhttp3.internal.okHttpName
3232
import okhttp3.internal.threadFactory
33+
import okhttp3.internal.threadName
3334

3435
/**
3536
* A set of worker threads that are shared among a set of task queues.
@@ -132,18 +133,15 @@ class TaskRunner(
132133
}
133134

134135
private fun runTask(task: Task) {
135-
val currentThread = Thread.currentThread()
136-
val oldName = currentThread.name
137-
currentThread.name = task.name
138-
139-
var delayNanos = -1L
140-
try {
141-
delayNanos = task.runOnce()
142-
} finally {
143-
this.withLock {
144-
afterRun(task, delayNanos)
136+
threadName(task.name) {
137+
var delayNanos = -1L
138+
try {
139+
delayNanos = task.runOnce()
140+
} finally {
141+
this.withLock {
142+
afterRun(task, delayNanos)
143+
}
145144
}
146-
currentThread.name = oldName
147145
}
148146
}
149147

0 commit comments

Comments
 (0)