By now, you have understood how to connect to the bucket and perform various operations using the Java SDK. We can conclude that there are two ways of connecting to the bucket:
Synchronously:
Cluster cluster = CouchbaseCluster.create(); Bucket bucket = cluster.openBucket();
Asynchronously:
AsyncBucket asyncBucket = bucket.async();
Couchbase SDKs based on Java and .Net are designed to be thread-safe for each operation. There is a class called CouchbaseEnvironment
that can be used to customize connection to the cluster.
How we create this environment is given in the following code:
CouchbaseEnvironment clusterEnv = DefaultCouchbaseEnvironment .builder() .computationPoolSize(5) .build(); Cluster cluster = CouchbaseCluster.create(clusterEnv, "ourserver.com");
You need to pass the CouchbaseEnvironment
object to the cluster factory method while creating the cluster...