原创转载请注明出处:http://agilestyle.iteye.com/blog/2395890

 

JDK IntroductionRuntime.getRuntime().addShutdownHook用法 

Code Demo

package org.fool.test;

public class TestShutdownHook {
    public static void main(String[] args) {
        Thread thread1 = new Thread(() -> System.out.println("Thread1..."));
        Thread thread2 = new Thread(() -> System.out.println("Thread2..."));
        Thread thread3 = new Thread(() -> System.out.println("Thread3..."));

        Thread shutdownHookThread1 = new Thread(() -> System.out.println("ShutdownHook Thread1..."));
        Thread shutdownHookThread2 = new Thread(() -> System.out.println("ShutdownHook Thread2..."));
        Thread shutdownHookThread3 = new Thread(() -> System.out.println("ShutdownHook Thread3..."));

        Runtime.getRuntime().addShutdownHook(shutdownHookThread1);
        Runtime.getRuntime().addShutdownHook(shutdownHookThread2);
        Runtime.getRuntime().addShutdownHook(shutdownHookThread3);
        thread1.start();
        thread2.start();
        thread3.start();
    }
}

 

Console Output

Runtime.getRuntime().addShutdownHook用法 

相关文章:

  • 2021-08-20
  • 2021-12-31
  • 2022-12-23
  • 2022-01-13
  • 2021-11-12
  • 2021-10-07
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-19
  • 2021-07-25
  • 2021-06-26
  • 2022-12-23
相关资源
相似解决方案