diff --git a/alts/src/main/java/io/grpc/alts/AltsChannelBuilder.java b/alts/src/main/java/io/grpc/alts/AltsChannelBuilder.java index 81dd75eab46..af80a3c5dda 100644 --- a/alts/src/main/java/io/grpc/alts/AltsChannelBuilder.java +++ b/alts/src/main/java/io/grpc/alts/AltsChannelBuilder.java @@ -38,7 +38,7 @@ public final class AltsChannelBuilder extends ForwardingChannelBuilder2 serverBuilder, int port, Collection { + // Use stderr here since the logger may have been reset by its JVM shutdown hook. + System.err.println("*** shutting down gRPC server since JVM is shutting down"); + try { + RouteGuideServer.this.stop(); + } catch (InterruptedException e) { + e.printStackTrace(System.err); } - }); + System.err.println("*** server shut down"); + })); } /** Stop serving requests and shutdown resources. */ @@ -120,7 +117,7 @@ public static void main(String[] args) throws Exception { private static class RouteGuideService extends RouteGuideGrpc.RouteGuideImplBase { private final Collection features; private final ConcurrentMap> routeNotes = - new ConcurrentHashMap>(); + new ConcurrentHashMap<>(); RouteGuideService(Collection features) { this.features = features; @@ -251,7 +248,7 @@ public void onCompleted() { * Get the notes list for the given location. If missing, create it. */ private List getOrCreateNotes(Point location) { - List notes = Collections.synchronizedList(new ArrayList()); + List notes = Collections.synchronizedList(new ArrayList<>()); List prevNotes = routeNotes.putIfAbsent(location, notes); return prevNotes != null ? prevNotes : notes; }