Is there a way to take an argument in a callable method?

后端 未结 7 1021
Happy的楠姐
Happy的楠姐 2020-12-23 16:41

I have created a piece of code which takes an IP address (from main method in another class) and then loops through a range of IP addresses pinging each one as it goes. I ha

相关标签:
7条回答
  • 2020-12-23 17:09

    Put some (final) fields in your doPing class, and a constructor that initializes them, then pass the values you want to use in call() to the constructor of doPing:

    public class DoPing implements Callable<String>  {
         private final String ipToPing;
    
         public DoPing(String ip) {
             this.ipToPing = ip;
         }
         
         public String call() {
             // use ipToPing
         }
    }
    
    0 讨论(0)
提交回复
热议问题