Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Experiment] default to Loom on #8168

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ subprojects {

configure<JavaPluginExtension> {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
languageVersion.set(JavaLanguageVersion.of(21))
}
}

Expand Down Expand Up @@ -202,7 +202,7 @@ subprojects {
}

tasks.withType<JavaCompile> {
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
sourceCompatibility = JavaVersion.VERSION_21.toString()
targetCompatibility = JavaVersion.VERSION_1_8.toString()
}
}
Expand All @@ -213,7 +213,7 @@ subprojects {
dokkaSourceSets.configureEach {
reportUndocumented.set(false)
skipDeprecated.set(true)
jdkVersion.set(8)
jdkVersion.set(21)
perPackageOption {
matchingRegex.set(".*\\.internal.*")
suppress.set(true)
Expand Down
12 changes: 11 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,17 @@ 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.SuppressSignatureCheck
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 @@ -88,12 +92,18 @@ class Dispatcher() {

private var executorServiceOrNull: ExecutorService? = null

@SuppressSignatureCheck
@get:Synchronized
@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
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package okhttp3.internal

import java.lang.annotation.Documented
import kotlin.annotation.AnnotationRetention.BINARY
import kotlin.annotation.AnnotationTarget.CLASS
import kotlin.annotation.AnnotationTarget.CONSTRUCTOR
import kotlin.annotation.AnnotationTarget.FUNCTION
import kotlin.annotation.AnnotationTarget.*

@Retention(BINARY)
@Documented
@Target(CONSTRUCTOR, CLASS, FUNCTION)
@Target(CONSTRUCTOR, CLASS, FUNCTION, PROPERTY)
internal annotation class SuppressSignatureCheck
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")
}
}
}
Loading