Skip to content

Commit

Permalink
Experiment with Loom on
Browse files Browse the repository at this point in the history
  • Loading branch information
yschimke committed Dec 30, 2023
1 parent e09a018 commit 8dac5cc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 9 additions & 1 deletion okhttp/src/main/kotlin/okhttp3/Dispatcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ import java.util.ArrayDeque
import java.util.Collections
import java.util.Deque
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.concurrent.Executors.newVirtualThreadPerTaskExecutor
import java.util.concurrent.SynchronousQueue
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit
import okhttp3.internal.assertThreadDoesntHoldLock
import okhttp3.internal.connection.RealCall
import okhttp3.internal.connection.RealCall.AsyncCall
import okhttp3.internal.okHttpName
import okhttp3.internal.platform.Platform
import okhttp3.internal.threadFactory

/**
Expand Down Expand Up @@ -92,8 +95,13 @@ class Dispatcher() {
@get:JvmName("executorService") val executorService: ExecutorService
get() {
if (executorServiceOrNull == null) {
executorServiceOrNull = ThreadPoolExecutor(0, Int.MAX_VALUE, 60, TimeUnit.SECONDS,
executorServiceOrNull = if (Platform.majorVersion < 21) {
ThreadPoolExecutor(0, Int.MAX_VALUE, 60, TimeUnit.SECONDS,
SynchronousQueue(), threadFactory("$okHttpName Dispatcher", false))
} else {
@Suppress("Since15")
newVirtualThreadPerTaskExecutor()
}
}
return executorServiceOrNull!!
}
Expand Down
11 changes: 11 additions & 0 deletions okhttp/src/main/kotlin/okhttp3/internal/platform/Platform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,16 @@ open class Platform {
}
return result.readByteArray()
}

val majorVersion: Int by lazy {
when (val jvmSpecVersion = getJvmSpecVersion()) {
"1.8" -> 8
else -> jvmSpecVersion.toInt()
}
}

fun getJvmSpecVersion(): String {
return System.getProperty("java.specification.version", "unknown")
}
}
}

0 comments on commit 8dac5cc

Please sign in to comment.