Skip to content

AutoRest : Main thread does not terminate. #622

Description

@m-moris

I have tried 1.0 beta.
When I use an asynchronous method, main thread does not terminate.
It looks like OkHttp threads are still remain.

Does anyone know any solution?

package sample.autorest;

import java.io.IOException;

import com.microsoft.azure.CloudException;
import com.microsoft.azure.credentials.ApplicationTokenCredentials;
import com.microsoft.azure.management.compute.ComputeManagementClient;
import com.microsoft.azure.management.compute.ComputeManagementClientImpl;
import com.microsoft.azure.management.compute.models.VirtualMachine;
import com.microsoft.rest.ServiceCall;
import com.microsoft.rest.ServiceCallback;
import com.microsoft.rest.ServiceResponse;

import okhttp3.logging.HttpLoggingInterceptor;

public class App3 {

    public static void main(String[] args) throws CloudException, IllegalArgumentException, IOException, InterruptedException {

        String subscriptionId = "<<your subscription id>>";
        String tenantId = "<<your tenant id>>";
        String clientId = "<<your client id>>";
        String clientKey = "<<your client key>>";

        ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(
                clientId, tenantId, clientKey, null);

        ComputeManagementClient client = new ComputeManagementClientImpl(credentials);
        client.setSubscriptionId(subscriptionId);
        client.setLogLevel(HttpLoggingInterceptor.Level.BODY);

        String rg = "your resource-group-name";
        String rs = "your vm name";

        ServiceCallback<VirtualMachine> serviceCallback = new ServiceCallback<VirtualMachine>() {
            @Override
            public void failure(Throwable t) {
                System.err.println("failed");
            }

            @Override
            public void success(ServiceResponse<VirtualMachine> result) {
                VirtualMachine vm = result.getBody();
                System.out.println(vm.getId());
            }
        };
        ServiceCall async = client.getVirtualMachinesOperations().getAsync(rg, rs, "instanceview", serviceCallback);
        System.out.println("done");
    }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions