How can I avoid blocking with Java ServerSocket?

前端 未结 3 2161
长发绾君心
长发绾君心 2021-02-19 15:56

Im working on a socket listener that has to listen on 2 ports for 2 types of data( port 80 and port 81). These data are very similar as in the kind of operations that are perfor

3条回答
  •  眼角桃花
    2021-02-19 16:42

    Many frameworks, such as Apache MINA and Netty, have been implemented based on Java NIO to boost non-blocking IO programming. I strongly recommend them to make your NIO programming a joy, rather than a nightmare. They fit your problem.

    In addition, try to use an efficient protocol both in transport message size and encode/decode (serialize/deserialize) performance. Google Protocol Buffers is a reliable solution in this area. Also take a look at Kryo and KryoNet. They can be helpful.

提交回复
热议问题