Non-blocking (async) DNS resolving in Java

前端 未结 6 661
一生所求
一生所求 2021-02-05 02:30

Is there a clean way to resolve a DNS query (get IP by hostname) in Java asynchronously, in non-blocking way (i.e. state machine, not 1 query = 1 thread - I\'d like to run tens

6条回答
  •  甜味超标
    2021-02-05 03:15

    You have multiple options

    Option 1: Java 5 Executors

    1. A Fixed thread pool: Executors.newFixedThreadPool(int)
    2. Future: A Future represents the result of an asynchronous computation. Methods are provided to check if the computation is complete, to wait for its completion, and to retrieve the result of the computation.

    Option 2: JMS with MessageListener

    1. Requires dependency on JMS Provider etc.

    Option 2: Actor based framework

    You can scale this well with this.Look at Akka.

提交回复
热议问题