IpService implements Initializable { public IpInfo findIpInfoByString(String ip) { try { String[] segments = ip.split("\\."); if (segments.length != 4) { return null; } long ip_num = Long.parseLong(segments[0]) << 24; ip_num += Integer.parseInt(segments[1]) << 16; ip_num += Integer.parseInt(segments[2]) << 8; ip_num += Integer.parseInt(segments[3]); return findIpInfo(ip_num); } catch (Exception e) { return null; } }  IpInfo findIpInfoByString(String ip); void initForeignIpTable(InputStream ipFile); @Override void initialize(); void initIpTable(InputStream ipFile);  }
@Test public void test() throws Exception { IpService service = (IpService) lookup(IpService.class); for (int i = 0; i < 10000; i++) { String ip = i % 255 + "." + i % 255 + "." + i % 255 + "." + i % 255; IpInfo info = service.findIpInfoByString(ip); if (info != null) { System.out.print(ip + " " + info.getChannel()); System.out.print(" " + info.getCity()); System.out.println(" " + info.getProvince()); } } }
@Test public void test2() throws InterruptedException { service = (IpService2) lookup(IpService2.class); int count = 1000; for (int j = 0; j < count; j++) { Threads.forGroup().start(new Runnable() { @Override public void run() { long start = System.currentTimeMillis(); for (int i = 0; i < 10000; i++) { String ip = (int) (Math.random() * 255) + "." + (int) (Math.random() * 255) + "." + (int) (Math.random() * 255) + "." + (int) (Math.random() * 255); IpInfo info = service.findIpInfoByString(ip); if (info == null) { System.out.println("error"); } } long end = System.currentTimeMillis(); System.out.println("TIME: " + (end - start)); result.add(end - start); } }); } while (result.size() < count) { Thread.sleep(1000); } long sum = 0; for (int i = 0; i < count; i++) { sum += result.get(i); } System.out.println(sum / count); }