HttpClient is Now AutoCloseable in Java 21

Поділитися
Вставка
  • Опубліковано 17 чер 2024
  • HttpClient has been updated to be AutoCloseable in Java 21. Let's take a look!
    Article: inside.java/sip/092
    Tags: #OpenJDK #jdk21 #Java21 #Java #InsideJava
  • Наука та технологія

КОМЕНТАРІ • 19

  • @user-np6du6nu9l
    @user-np6du6nu9l 6 місяців тому

    Thanks 😊

  • @svalyavasvalyava9867
    @svalyavasvalyava9867 6 місяців тому +1

    thank you for this video 😊

    • @java
      @java  6 місяців тому

      You're welcome 😊

  • @thoriig3887
    @thoriig3887 6 місяців тому

    did you any tests with the new http client regarding ssl handshakes and "infinitely raising client caches"(softreferences). using 2/3 of the total heap with no hits on entries all all... ;D
    done a workaround by limiting the cache with a property. dont know if its a flaw in the sslcontext implementation itself or the combination of apache httpclient 4.5+spring resttemplate+sslcontext. sadly timeout is hardcoded 24h at jdk11 .0..21
    if the new internal http client would be comparable regarding performance and avoiding that client cache problem, it would be another point on the plus side to upgrade to jdk21 and kill another dependency. (convincing management)

  • @karaal44
    @karaal44 6 місяців тому

    👌

  • @giovanninabil6950
    @giovanninabil6950 6 місяців тому

    yeah, that's really a "Big Update" 🙂

  • @KhazanViktor
    @KhazanViktor 6 місяців тому +4

    And what's about ExecutorServices?)

  • @JumBitre
    @JumBitre 6 місяців тому +1

    First!

  • @nagarajasosaleramaswamy5334
    @nagarajasosaleramaswamy5334 6 місяців тому

    then why do i get this error (i am using JDK 21) ?
    java: incompatible types: try-with-resources not applicable to variable type
    (java.net.http.HttpClient cannot be converted to java.lang.AutoCloseable)

    • @nipafx
      @nipafx 6 місяців тому +1

      You get this error because you're not running on JDK 21+. I know you wrote that you are but that can't be right - it's in the Javadoc after all: docs.oracle.com/en/java/javase/21/docs/api/java.net.http/java/net/http/HttpClient.html (and it works on my machine). Maybe put `System.out.println(Runtime.version());` into your `main` method to see which version is really building/running your code?