Java Network Sockets + Virtual Threads = Cool!

Поделиться
HTML-код
  • Опубликовано: 1 ноя 2024

Комментарии • 29

  • @DenaTollefson
    @DenaTollefson 6 месяцев назад +6

    Fantastic explanation of how networks in Java work, Will! Awesome socket programming tutorial 🤗

  • @NatiShen
    @NatiShen 6 месяцев назад +7

    I was the one asking for this video, you have no idea how much I appreciate you right now.
    Your videos are some of the best out there when it comes to Java. I am sending your videos to everyone in my college.

    • @willtollefson
      @willtollefson  6 месяцев назад +3

      Glad you liked the video! Hopefully this is what you were looking for. Let me know if you have any other requests :)

    • @NatiShen
      @NatiShen 6 месяцев назад +1

      Maybe you already have one but perhaps you could do a video on IO?
      I found it hard to figure out what's a buffered reader, why we insert another file reader inside, what's an output stream etc etc.
      Also, let's say I wanna learn a new api and it's structure. How would you do it ?

    • @willtollefson
      @willtollefson  5 месяцев назад

      I did a high level video on file IO here a little while back: ruclips.net/video/Ldx3NdGk86o/видео.html
      I don't go into a lot of detail on that video, but hopefully that touches on some of your questions.
      Learning a new API can be fun or frustrating depending on the documentation and examples available. I usually try to approach the API with a high level picture in mind of what its intended to do, and then I find the simplest example that accomplishes that. After I start learning the API's jargon, I'll play around with it some more and make sure I understand it, sometimes peaking at the source code if its available. In my experience following an example without context isn't super helpful, nor is diving head first into the documentation without looking at the bigger picture from time to time.

  • @brazenintellect364
    @brazenintellect364 6 месяцев назад +3

    This was an amazing walk through. Network programming in general is super interesting.
    I would really appreciate it if you cover the NIO way of socket programming.

    • @willtollefson
      @willtollefson  6 месяцев назад +3

      I think network programming is cool too. I’ll be sure to make a follow up video talking about NIO sockets as well. Thanks for the comment!

    • @willtollefson
      @willtollefson  5 месяцев назад +2

      Here you go! ruclips.net/video/h76n2R4HRts/видео.html

    • @brazenintellect364
      @brazenintellect364 5 месяцев назад +1

      @@willtollefson Thank you so much🙌

  • @darrowthered7665
    @darrowthered7665 13 дней назад +1

    Great content! Your videos deserve a lot more views. Please keep making Java videos.

    • @willtollefson
      @willtollefson  13 дней назад +1

      Thanks so much. I’ll keep posting Java content when I can!

  • @rahhi9792
    @rahhi9792 6 месяцев назад +5

    Appreciate you sharing this, Nice content. Next video on Websocket?

    • @willtollefson
      @willtollefson  6 месяцев назад +3

      Good idea on WebSocket. Are you looking for a video on the protocol, or the javax.websocket package and associated examples?

    • @rahhi9792
      @rahhi9792 6 месяцев назад +2

      @@willtollefson I am looking for example such as chat app or any other eg (serverbrowser). it would be great if you explain how this technology works.

    • @willtollefson
      @willtollefson  6 месяцев назад +2

      @@rahhi9792awesome - I’ll plan on making a video on that soon!

  • @Michaelno
    @Michaelno 6 месяцев назад +3

    Coders who know networking are cool. 😎

  • @horimberebertrand3220
    @horimberebertrand3220 4 дня назад +1

    Hello. thank you for this video. You declared "final int PORT_NUMBER = 12345;" in the "Main" class and used it in the "start()" method of "MyClient" class. However, "MyServer" class returns 50071 or 50072 when it calls "client.getPort()". Could you please explain why the client port number returned is 50071 and not 12345 ?

    • @willtollefson
      @willtollefson  4 дня назад

      Happy to do so! PORT_NUMBER is referring to the source port number for the server specifically. The reason both the client and server need this is because the server uses it to bind the server socket and the client uses it as a destination port when it talks to the server. The port that is printed out in the output window is the client's source port (aka the server destination port), which by default is determined by the OS when the client creates the TCP socket.

  • @devilhorrible6715
    @devilhorrible6715 6 месяцев назад +2

    Are virtual threads being updated in the tomcat server?? If so, what is the version??

    • @willtollefson
      @willtollefson  6 месяцев назад +1

      Yes, Tomcat is adding support for these! I haven't personally tried it, but the docs seem to indicate that virtual thread executors are avilable in Tomcat 11 at least, and there might be some support in Tomcat 10.

    • @devilhorrible6715
      @devilhorrible6715 6 месяцев назад +2

      @@willtollefson Thanks for the update.

  • @구명수-h7c
    @구명수-h7c 5 месяцев назад +1

    Hello, I'm watching your video in Korea :)
    But if you don't use NIO-socket for reading or writing, then isn't it essentially the same as using multi-platform threads? I'm a bit confused. Thank you for your nice video!

    • @willtollefson
      @willtollefson  5 месяцев назад +2

      Thanks for the question! If the server has to spin off a thread per request (or thread per client), then you have two main options:
      1. Platform threads (the original way)
      2. Virtual threads
      In Java 21 and later, most of the time you'll want do option 2 due to how virtual threads are implemented. Most of the time you'll get a perceived performance boost because the JVM is more efficiently utilizing CPU resources across threads.

  • @Shuvooa
    @Shuvooa 4 месяца назад

    Please don't use `var`. It irritates the mind.

    • @willtollefson
      @willtollefson  4 месяца назад +1

      Personal preference I suppose 🙂 I know folks who use it every chance they get and others that wish it was never added to the language. What are your thoughts on it? I agree with a lot of what is stated here: openjdk.org/projects/amber/guides/lvti-style-guide