Database Reference
In-Depth Information
this.client = client;
this.itemLimit = itemLimit;
this.totalSegments = totalSegments;
this.segment = segment;
}
@Override
void run() {
Map<String, AttributeValue> exclusiveStartKey = null;
try {
while(true) {
ScanRequest scanRequest = new ScanRequest()
.withTableName("Tbl_Book")
.withLimit(itemLimit)
.withExclusiveStartKey(exclusiveStartKey)
.withTotalSegments(totalSegments)
.withSegment(segment);
ScanResult result = client.scan(scanRequest);
//Use result.getItems()to print or process scan result
exclusiveStartKey = result.getLastEvaluatedKey();
if (exclusiveStartKey == null)
break;
}
} catch (AmazonServiceException ase) {
System.out.println(ase.getMessage());
}
}}
The second method is the abstract method (run) available in the Runnable interface. We
need to write the scanning-related requests inside this method. Inside this method, we con-
figure our ScanRequest instance with values initialized in the constructor using corres-
ponding methods. We can retrieve the output of every ScanRequest using the
getItems() method available in the ScanResult class. Everything remains the
same. The only difference here is, instead of executing (writing) the scan request inside a
method, we are writing it inside the run method.
We will write a method (see the following code block) to call the ParallelScanner
class. First, we will create an instance of the
java.util.concurrent.ExecutorService class with three threads. The
Search WWH ::




Custom Search