Skip to main content

Posts

Showing posts from January, 2020

My favorite features when upgrade from java 8 to java 11

1. A new HttpClient/HttpRequest/HttpResponse/WebSocket: HttpRequest request = HttpRequest.newBuilder()   .uri(new URI("https://postman-echo.com/get"))   .GET()   .build(); HttpResponse<String> response = HttpClient.newHttpClient()   .send(request, HttpResponse.BodyHandler.asString()); 2. Process handler ProcessHandle self = ProcessHandle.current(); long PID = self.getPid(); ProcessHandle.Info procInfo = self.info();   Optional<String[]> args = procInfo.arguments(); Optional<String> cmd =  procInfo.commandLine(); Optional<Instant> startTime = procInfo.startInstant(); Optional<Duration> cpuUsage = procInfo.totalCpuDuration() 3. Destroying child process childProc = ProcessHandle.current().children(); childProc.forEach(procHandle -> {     assertTrue("Could not kill process " + procHandle.getPid(), procHandle.destroy()); }); 4. JSheel command line to verify the simple snip code. 5. Immutable Set and Map Se