2019-11-19 一段可以把MacOS搞重启的java代码

/**
 * @author Albert
 */
@Slf4j
public class MacCrash {

    private static final AtomicInteger index = new AtomicInteger();

    public static void main(String[] args) {
        log.info("start");
        run();
    }

    public static void run() {

        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1000, Integer.MAX_VALUE, Integer.MAX_VALUE, TimeUnit.DAYS, new ArrayBlockingQueue(1));
        ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();

        scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                try {
                    for (;;) {
                        KeyStreamingChannel accept = this::accept;
                        accept.onKey("abc");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            private void accept(String url) {
                threadPoolExecutor.submit(() -> System.out.println(index.getAndIncrement()));
            }
        }, 0, 1, TimeUnit.SECONDS);

    }

}

你可能感兴趣的:(2019-11-19 一段可以把MacOS搞重启的java代码)