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

Synchronise ForkJoinPool port with JSR-166 changes for JDK 19 #3243

Merged
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Expert Group and released to the public domain, as explained at
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// revision 1.72
package java.util.concurrent

import scala.scalanative.runtime.{Intrinsics, fromRawPtr}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package concurrent

import java.security.{PrivilegedAction, PrivilegedExceptionAction}

trait ExecutorService extends Executor {
trait ExecutorService extends Executor with AutoCloseable {

def shutdown(): Unit

Expand Down Expand Up @@ -45,4 +45,26 @@ trait ExecutorService extends Executor {
unit: TimeUnit
): T

// Since JDK 19
override def close(): Unit = {
var terminated = isTerminated()
if (!terminated) {
shutdown()
var interrupted = false
while (!terminated) {
try terminated = awaitTermination(1L, TimeUnit.DAYS)
catch {
case e: InterruptedException =>
if (!interrupted) {
shutdownNow()
interrupted = true
}
}
}
if (interrupted) {
Thread.currentThread().interrupt()
}
}
}

}