2

I am developing an app in Java (Kotlin :X) that uses the Google Photos Api.

I am stuck in a flow where I may want to cancel the current client initialization attempt and try again.

val settings = PhotosLibrarySettings.newBuilder()
    .setCredentialsProvider(
        FixedCredentialsProvider.create(
            getUserCredentials(credentialsPath, SCOPES, email)
        )
    )
    .build()

// let the Thread hanging until a successful initialization :/
return PhotosLibraryClient.initialize(settings)

But unfortunately, I did not find any way to do this besides enveloping the PhotosLibraryClient.initialize(settings) call in a Thread and calling the deprecated method Thread#stop().

If I do this call twice (on different threads), without successfully stopping one of the client initializations, the following exception is thrown: java.io.IOException: java.net.BindException: Address already in use (Bind failed).


How can I successfully stop a client initialization attempt without calling Thread#stop()?

Augusto Carmo
  • 4,386
  • 2
  • 28
  • 61

0 Answers0