Skip to content

Async methods are not actually Async. They seem to be blocking #2

@rajdeeprath

Description

@rajdeeprath

PostDeleteChecker checker = new PostDeleteChecker(azure, vmResourceGroup, vmName);
azure.resourceGroups().deleteByNameAsync(vmResourceGroup.name(), checker.deleteServiceCallbackHandler);

ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.execute(checker);
executorService.shutdown();
System.out.println("here");


class PostDeleteChecker implements Runnable
{
Azure azure;
ResourceGroup resourceGroup;
String vmName;

public PostDeleteChecker(Azure azure, ResourceGroup vmResourceGroup, String vmName) {
	this.azure = azure;
	this.resourceGroup = vmResourceGroup;
	this.vmName = vmName;
}

@Override
public void run() {			
	logger.info("Waiting for operation completion...");
}
		
private ServiceCallback<Void> deleteServiceCallbackHandler = new ServiceCallback<Void>(){

	@Override
	public void failure(Throwable arg0) 
	{
		logger.error("Delete operation Error! " + arg0.getMessage());				
	}

	@Override
	public void success(Void arg0) 
	{
		logger.info("Delete operation Success!");
	}
	
};

public ServiceCallback<Void> getDeleteServiceCallbackHandler() {
	return deleteServiceCallbackHandler;
}

}	

If you run the above code, neither System.out.println("here"); nor logger.info("Waiting for operation completion..."); gets executed until the resource group has been deleted completed. Then how is this asynchronous in any way?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions