Example: Java App Engine standard environment
This example is an App Engine application, written in
Java, that writes some "hello world" greetings to a Bigtable
table and reads them back. The application runs on Google Cloud in the
App Engine standard environment. The application
uses the Java 8 runtime. The code for this application is in the GitHub
repository GoogleCloudPlatform/java-docs-samples, in the
directory appengine-java8/bigtable
.
Overview of the code sample
The code sample includes the following classes:
BigtableHelper
, which provides a connection to Bigtable.BigtableHelloWorld
, which writes to and reads from Bigtable.
BigtableHelper
BigtableHelper
provides a method to create a connection to
Bigtable. It also caches the connection and provides a method that
will retrieve the cached connection if it exists. Creating a connection is a
relatively expensive operation, so as a best practice you should always create a
single connection and reuse it.
BigtableHelloWorld
BigtableHelloWorld
is used to write a series of greetings to
Bigtable, read the greetings, and then display them. The class
gets a Bigtable connection from BigtableHelper
, uses the
connection to get a Table
object, which lets you to read and write values,
then uses the Table
object to write to and read from the table.