# DGraph Java Client Thread Pooling

**URL:** <https://discuss.dgraph.io/t/dgraph-java-client-thread-pooling/4918>\
**Category:** Dgraph\
**Created:** [August 13, 2019, 11:41am UTC](https://discuss.dgraph.io/t/dgraph-java-client-thread-pooling/4918 "2019-08-13T11:41:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jungleerohan](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jungleerohan/32/1866_2.png) [@jungleerohan](https://discuss.dgraph.io/u/jungleerohan)\
**Post date:** [August 13, 2019, 11:41am UTC](https://discuss.dgraph.io/t/dgraph-java-client-thread-pooling/4918/1 "2019-08-13T11:41:57Z")

</div>

I am using DGraphClient in Java. I have too many concurrent mutations and queries coming in at the same time.  
Do I need to a pool of DGrpahClient object or it is handled inside DGrphClient itself.

How does gRPC internally manage the concurrent Transactions? Please explain.

---

<div class="post-metadata">

**Author:** ![Atul\_nasir\_simida](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/atul_nasir_simida/32/11770_2.png) [@Atul\_nasir\_simida](https://discuss.dgraph.io/u/Atul_nasir_simida)\
**Post date:** [February 10, 2025, 11:29am UTC](https://discuss.dgraph.io/t/dgraph-java-client-thread-pooling/4918/2 "2025-02-10T11:29:40Z")

</div>

```auto
import io.dgraph.DgraphClient;
import io.dgraph.DgraphGrpc;
import io.dgraph.DgraphGrpc.DgraphStub;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;

public class DgraphExample {
    public static void main(String[] args) {
        // Create a gRPC channel
        ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 9080).usePlaintext().build();
        DgraphStub stub = DgraphGrpc.newStub(channel);
        DgraphClient dgraphClient = new DgraphClient(stub);

        // Create a thread pool for concurrent operations
        int threadPoolSize = 10;
        ExecutorService executorService = Executors.newFixedThreadPool(threadPoolSize);

        // Submit tasks to the thread pool
        for (int i = 0; i < 100; i++) {
            executorService.submit(() -> performOperation(dgraphClient));
        }

        // Shutdown the thread pool
        executorService.shutdown();
    }

    private static void performOperation(DgraphClient dgraphClient) {
        try {
            // Create a new transaction
            io.dgraph.Transaction txn = dgraphClient.newTransaction();

            // Perform a mutation or query
            String query = "{\n" +
                    " q(func: has(name)) {\n" +
                    " name\n" +
                    " }\n" +
                    "}";
            io.dgraph.Response response = txn.query(query);

            // Commit the transaction
            txn.commit();

            // Process the response
            System.out.println("Response: " + response.getJson().toStringUtf8());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

```
