Skip to content

Commit c02460b

Browse files
authored
Fix OpenCensus thread cleanup error and other issues. (GoogleCloudPlatform#1246)
1 parent 1fe3270 commit c02460b

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

opencensus/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
</executions>
7575
<configuration>
7676
<mainClass>com.example.opencensus.Quickstart</mainClass>
77+
<cleanupDaemonThreads>false</cleanupDaemonThreads>
7778
</configuration>
7879
</plugin>
7980
</plugins>

opencensus/src/main/java/com/example/opencensus/Quickstart.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static void main(String[] args) throws IOException, InterruptedException
5151
// Register the view. It is imperative that this step exists,
5252
// otherwise recorded metrics will be dropped and never exported.
5353
View view = View.create(
54-
Name.create("task_latency_distribution_4"),
54+
Name.create("task_latency_distribution"),
5555
"The distribution of the task latencies.",
5656
LATENCY_MS,
5757
Aggregation.Distribution.create(LATENCY_BOUNDARIES),
@@ -68,7 +68,6 @@ public static void main(String[] args) throws IOException, InterruptedException
6868
StackdriverStatsExporter.createAndRegister();
6969
// [END setup_exporter]
7070

71-
// [START example_code]
7271
// Record 100 fake latency values between 0 and 5 seconds.
7372
Random rand = new Random();
7473
for (int i = 0; i < 100; i++) {
@@ -81,8 +80,9 @@ public static void main(String[] args) throws IOException, InterruptedException
8180
// live for at least the interval past any metrics that must be collected, or some risk being
8281
// lost if they are recorded after the last export.
8382

83+
System.out.println(String.format(
84+
"Sleeping %d seconds before shutdown to ensure all records are flushed.", EXPORT_INTERVAL));
8485
Thread.sleep(TimeUnit.MILLISECONDS.convert(EXPORT_INTERVAL, TimeUnit.SECONDS));
85-
// [END example_code]
8686
}
8787
}
8888
// [END monitoring_opencensus_metrics_quickstart]

0 commit comments

Comments
 (0)