msgraph-sdk-java icon indicating copy to clipboard operation
msgraph-sdk-java copied to clipboard

Is GraphServiceClient threadsafe?

Open siddhartha-ghosh opened this issue 1 year ago • 2 comments

Hi,

I am using msgraph sdk to get 'User' details in an application. Initialized the GraphServiceClient for app-only authentication as specified in the tutorial: https://learn.microsoft.com/en-us/graph/tutorials/java-app-only?tabs=aad&tutorial-step=3.

I want to query the 'users' using certain filter and select criteria, e.g.

_appClient.users().get(requestConfig -> {
        requestConfig.queryParameters.filter = "displayName startsWith \'A\'";
        requestConfig.queryParameters.select = new String[] { "displayName", "id", "mail" };
        requestConfig.queryParameters.top = 25;
        requestConfig.queryParameters.orderby = new String[] { "displayName" };
    });

However, this request may happen from the context of different threads. My queries are:

  • Does each thread need to instantiate GraphServiceClient separately, or, can we initialize once and share across threads?
  • If _appClient (i.e the instance of GraphServiceClient) can be shared, is it thread-safe or do we need to synchronize access to it?

Any insight will be helpful.

The following artifact versions are used: microsoft-graph (v 6.20.0) and azure-identity (1.14.1).

siddhartha-ghosh avatar Nov 14 '24 12:11 siddhartha-ghosh

Great question @siddhartha-ghosh. I will get back soon after some investigations

Ndiritu avatar Dec 02 '24 21:12 Ndiritu

Hi @Ndiritu , is there any update on this issue? Thanks in advance. Regards,

siddhartha-ghosh avatar Jan 08 '25 06:01 siddhartha-ghosh