public static void main(String[] args) throws Exception { int N = 6000; if (args.length >= 1) N = Integer.parseInt(args[0]); Crb = new double[N + 7]; Cib = new double[N + 7]; double invN = 2.0 / N; for (int i = 0; i < N; i++) { Cib[i] = i * invN - 1.0; Crb[i] = i * invN - 1.5; } yCt = new AtomicInteger(); out = new byte[N][(N + 7) / 8]; Thread[] pool = new Thread[2 * Runtime.getRuntime().availableProcessors()]; for (int i = 0; i < pool.length; i++) pool[i] = new Thread() { public void run() { int y; while ((y = yCt.getAndIncrement()) < out.length) putLine(y, out[y]); } }; for (Thread t : pool) t.start(); for (Thread t : pool) t.join(); OutputStream stream = new BufferedOutputStream(System.out); stream.write(("P4\n" + N + " " + N + "\n").getBytes()); for (int i = 0; i < N; i++) stream.write(out[i]); stream.close(); }
/** * Checks if address can be reached using one argument InetAddress.isReachable() version or ping * command if failed. * * @param addr Address to check. * @param reachTimeout Timeout for the check. * @return {@code True} if address is reachable. */ public static boolean reachableByPing(InetAddress addr, int reachTimeout) { try { if (addr.isReachable(reachTimeout)) return true; String cmd = String.format("ping -%s 1 %s", U.isWindows() ? "n" : "c", addr.getHostAddress()); Process myProc = Runtime.getRuntime().exec(cmd); myProc.waitFor(); return myProc.exitValue() == 0; } catch (IOException ignore) { return false; } catch (InterruptedException ignored) { Thread.currentThread().interrupt(); return false; } }