{"id":10006712,"date":"2022-10-21T19:01:10","date_gmt":"2022-10-21T11:01:10","guid":{"rendered":"https:\/\/ityet.com\/?p=10006712"},"modified":"2022-10-21T19:01:10","modified_gmt":"2022-10-21T11:01:10","slug":"%e6%b1%82%e6%b1%82%e4%bd%a0%e4%bb%ac%e5%88%ab%e5%86%8d%e7%94%a8-kill-9-%e4%ba%86%ef%bc%8c%e8%bf%99%e6%89%8d%e6%98%af-spring-boot-%e5%81%9c%e6%9c%ba%e7%9a%84%e6%ad%a3%e7%a1%ae%e6%96%b9%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10006712","title":{"rendered":"\u6c42\u6c42\u4f60\u4eec\u522b\u518d\u7528 kill -9 \u4e86\uff0c\u8fd9\u624d\u662f Spring Boot \u505c\u673a\u7684\u6b63\u786e\u65b9\u5f0f\uff01\uff01\uff01"},"content":{"rendered":"<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc3b2f\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u518d\u8c08\u4e3a\u4e86\u63d0\u9192\u660e\u77e5\u6545\u72af\uff08\u5728\u4e00\u5751\u91cc\u8fed\u5012\u4e24\u6b21\u4e0d\u662f\u4e0d\u591a\u89c1\uff09\uff0c\u7531\u4e8e\u4e1a\u52a1\u7cfb\u7edf\u4e2d\u5927\u91cf\u4f7f\u7528\u4e86<code>spring Boot embedded tomcat<\/code>\u7684\u6a21\u5f0f\u8fd0\u884c\uff0c\u5728\u4e00\u4e9b\u8fd0\u7ef4\u811a\u672c\u4e2d\u7ecf\u5e38\u770b\u5230Linux \u4e2d <code>kill<\/code> \u6307\u4ee4\uff0c\u7136\u800c\u5b83\u7684\u4f7f\u7528\u4e5f\u6709\u4e9b\u8bb2\u7a76\uff0c\u8981\u601d\u8003\u5982\u4f55\u80fd\u505a\u5230\u4f18\u96c5\u505c\u673a\u3002<\/p>\n<hr>\n<h3>\u4f55\u4e3a\u4f18\u96c5\u5173\u673a<\/h3>\n<p>\u5c31\u662f\u4e3a\u786e\u4fdd\u5e94\u7528\u5173\u95ed\u65f6\uff0c\u901a\u77e5\u5e94\u7528\u8fdb\u7a0b\u91ca\u653e\u6240\u5360\u7528\u7684\u8d44\u6e90<\/p>\n<ul>\n<li>\u7ebf\u7a0b\u6c60\uff0cshutdown\uff08\u4e0d\u63a5\u53d7\u65b0\u4efb\u52a1\u7b49\u5f85\u5904\u7406\u5b8c\uff09\u8fd8\u662fshutdownNow\uff08\u8c03\u7528 <code>Thread.interrupt<\/code>\u8fdb\u884c\u4e2d\u65ad\uff09<\/li>\n<li>socket \u94fe\u63a5\uff0c\u6bd4\u5982\uff1anetty\u3001mq<\/li>\n<li>\u544a\u77e5\u6ce8\u518c\u4e2d\u5fc3\u5feb\u901f\u4e0b\u7ebf\uff08\u9760\u5fc3\u8df3\u673a\u5236\u5ba2\u670d\u65e9\u90fd\u8df3\u8d77\u6765\u4e86\uff09\uff0c\u6bd4\u5982\uff1aeureka<\/li>\n<li>\u6e05\u7406\u4e34\u65f6\u6587\u4ef6\uff0c\u6bd4\u5982\uff1apoi<\/li>\n<li>\u5404\u79cd\u5806\u5185\u5806\u5916\u5185\u5b58\u91ca\u653e<\/li>\n<\/ul>\n<p>\u603b\u4e4b\uff0c\u8fdb\u7a0b\u5f3a\u884c\u7ec8\u6b62\u4f1a\u5e26\u6765\u6570\u636e\u4e22\u5931\u6216\u8005\u7ec8\u7aef\u65e0\u6cd5\u6062\u590d\u5230\u6b63\u5e38\u72b6\u6001\uff0c\u5728\u5206\u5e03\u5f0f\u73af\u5883\u4e0b\u8fd8\u53ef\u80fd\u5bfc\u81f4\u6570\u636e\u4e0d\u4e00\u81f4\u7684\u60c5\u51b5\u3002<\/p>\n<h3>kill\u6307\u4ee4<\/h3>\n<p><code>kill -9 pid<\/code> \u53ef\u4ee5\u6a21\u62df\u4e86\u4e00\u6b21\u7cfb\u7edf\u5b95\u673a\uff0c\u7cfb\u7edf\u65ad\u7535\u7b49\u6781\u7aef\u60c5\u51b5\uff0c\u800c<code>kill -15 pid<\/code> \u5219\u662f\u7b49\u5f85\u5e94\u7528\u5173\u95ed\uff0c\u6267\u884c\u963b\u585e\u64cd\u4f5c\uff0c\u6709\u65f6\u5019\u4e5f\u4f1a\u51fa\u73b0\u65e0\u6cd5\u5173\u95ed\u5e94\u7528\u7684\u60c5\u51b5\uff08\u7ebf\u4e0a\u7406\u60f3\u60c5\u51b5\u4e0b\uff0c\u662fbug\u5c31\u8be5\u5bfb\u6839\u6eaf\u6e90\uff09<\/p>\n<pre><code>#\u67e5\u770bjvm\u8fdb\u7a0bpid\njps\n#\u5217\u51fa\u6240\u6709\u4fe1\u53f7\u540d\u79f0\nkill -l\n \n# Windows\u4e0b\u4fe1\u53f7\u5e38\u91cf\u503c\n# \u7b80\u79f0  \u5168\u79f0    \u6570\u503c \n# INT   SIGINT     2       Ctrl+C\u4e2d\u65ad\n# ILL   SIGILL     4       \u975e\u6cd5\u6307\u4ee4\n# FPE   SIGFPE     8       floating point exception(\u6d6e\u70b9\u5f02\u5e38)\n# SEGV  SIGSEGV    11      segment violation(\u6bb5\u9519\u8bef)\n# TERM  SIGTERM    5       Software termination signal from kill(Kill\u53d1\u51fa\u7684\u8f6f\u4ef6\u7ec8\u6b62)\n# BREAK SIGBREAK   21      Ctrl-Break sequence(Ctrl+Break\u4e2d\u65ad)\n# ABRT  SIGABRT    22      abnormal termination triggered by abort call(Abort)\n \n#linux\u4fe1\u53f7\u5e38\u91cf\u503c\n# \u7b80\u79f0  \u5168\u79f0  \u6570\u503c  \n# HUP   SIGHUP      1    \u7ec8\u7aef\u65ad\u7ebf  \n# INT   SIGINT      2    \u4e2d\u65ad\uff08\u540c Ctrl + C\uff09        \n# QUIT  SIGQUIT     3    \u9000\u51fa\uff08\u540c Ctrl + \/\uff09         \n# KILL  SIGKILL     9    \u5f3a\u5236\u7ec8\u6b62         \n# TERM  SIGTERM     15    \u7ec8\u6b62         \n# CONT  SIGCONT     18    \u7ee7\u7eed\uff08\u4e0eSTOP\u76f8\u53cd\uff0c fg\/bg\u547d\u4ee4\uff09         \n# STOP  SIGSTOP     19    \u6682\u505c\uff08\u540c Ctrl + Z\uff09        \n#....\n \n#\u53ef\u4ee5\u7406\u89e3\u4e3a\u64cd\u4f5c\u7cfb\u7edf\u4ece\u5185\u6838\u7ea7\u522b\u5f3a\u884c\u6740\u6b7b\u67d0\u4e2a\u8fdb\u7a0b\nkill -9 pid \n#\u7406\u89e3\u4e3a\u53d1\u9001\u4e00\u4e2a\u901a\u77e5\uff0c\u7b49\u5f85\u5e94\u7528\u4e3b\u52a8\u5173\u95ed\nkill -15 pid\n#\u4e5f\u652f\u6301\u4fe1\u53f7\u5e38\u91cf\u503c\u5168\u79f0\u6216\u7b80\u5199\uff08\u5c31\u662f\u53bb\u6389SIG\u540e\uff09\nkill -l KILL<\/code><\/pre>\n<blockquote><p>\u601d\u8003\uff1ajvm\u662f\u5982\u4f55\u63a5\u53d7\u5904\u7406linux\u4fe1\u53f7\u91cf\u7684\uff1f<\/p><\/blockquote>\n<p>\u5f53\u7136\u662f\u5728jvm\u542f\u52a8\u65f6\u5c31\u52a0\u8f7d\u4e86\u81ea\u5b9a\u4e49<code>SignalHandler<\/code>\uff0c\u5173\u95edjvm\u65f6\u89e6\u53d1\u5bf9\u5e94\u7684handle\u3002<\/p>\n<pre><code>public interface SignalHandler {\n    SignalHandler SIG_DFL = new NativeSignalHandler(0L);\n    SignalHandler SIG_IGN = new NativeSignalHandler(1L);\n \n    void handle(Signal var1);\n}\nclass Terminator {\n    private static SignalHandler handler = null;\n \n    Terminator() {\n    }\n    \/\/jvm\u8bbe\u7f6eSignalHandler\uff0c\u5728System.initializeSystemClass\u4e2d\u89e6\u53d1\n    static void setup() {\n        if (handler == null) {\n            SignalHandler var0 = new SignalHandler() {\n                public void handle(Signal var1) {\n                    Shutdown.exit(var1.getNumber() + 128);\/\/\u8c03\u7528Shutdown.exit\n                }\n            };\n            handler = var0;\n \n            try {\n                Signal.handle(new Signal(&quot;INT&quot;), var0);\/\/\u4e2d\u65ad\u65f6\n            } catch (IllegalArgumentException var3) {\n                ;\n            }\n \n            try {\n                Signal.handle(new Signal(&quot;TERM&quot;), var0);\/\/\u7ec8\u6b62\u65f6\n            } catch (IllegalArgumentException var2) {\n                ;\n            }\n \n        }\n    }\n}<\/code><\/pre>\n<h3>Runtime.addShutdownHook<\/h3>\n<p>\u5728\u4e86\u89e3<code>Shutdown.exit<\/code>\u4e4b\u524d\uff0c\u5148\u770b<code>Runtime.getRuntime().addShutdownHook(shutdownHook);<\/code>\u5219\u662f\u4e3ajvm\u4e2d\u589e\u52a0\u4e00\u4e2a\u5173\u95ed\u7684\u94a9\u5b50\uff0c\u5f53jvm\u5173\u95ed\u7684\u65f6\u5019\u8c03\u7528\u3002<\/p>\n<pre><code>public class Runtime {\n    public void addShutdownHook(Thread hook) {\n        SecurityManager sm = System.getSecurityManager();\n        if (sm != null) {\n            sm.checkPermission(new RuntimePermission(&quot;shutdownHooks&quot;));\n        }\n        ApplicationShutdownHooks.add(hook);\n    }\n}\nclass ApplicationShutdownHooks {\n    \/* The set of registered hooks *\/\n    private static IdentityHashMap&lt;Thread, Thread&gt; hooks;\n    static synchronized void add(Thread hook) {\n        if(hooks == null)\n            throw new IllegalStateException(&quot;Shutdown in progress&quot;);\n \n        if (hook.isAlive())\n            throw new IllegalArgumentException(&quot;Hook already running&quot;);\n \n        if (hooks.containsKey(hook))\n            throw new IllegalArgumentException(&quot;Hook previously registered&quot;);\n \n        hooks.put(hook, hook);\n    }\n}\n\/\/\u5b83\u542b\u6570\u636e\u7ed3\u6784\u548c\u903b\u8f91\u7ba1\u7406\u865a\u62df\u673a\u5173\u95ed\u5e8f\u5217\nclass Shutdown {\n    \/* Shutdown \u7cfb\u5217\u72b6\u6001*\/\n    private static final int RUNNING = 0;\n    private static final int HOOKS = 1;\n    private static final int FINALIZERS = 2;\n    private static int state = RUNNING;\n    \/* \u662f\u5426\u5e94\u8be5\u8fd0\u884c\u6240\u4ee5finalizers\u6765exit? *\/\n    private static boolean runFinalizersOnExit = false;\n    \/\/ \u7cfb\u7edf\u5173\u95ed\u94a9\u5b50\u6ce8\u518c\u4e00\u4e2a\u9884\u5b9a\u4e49\u7684\u63d2\u69fd.\n    \/\/ \u5173\u95ed\u94a9\u5b50\u7684\u5217\u8868\u5982\u4e0b:\n    \/\/ (0) Console restore hook\n    \/\/ (1) Application hooks\n    \/\/ (2) DeleteOnExit hook\n    private static final int MAX_SYSTEM_HOOKS = 10;\n    private static final Runnable[] hooks = new Runnable[MAX_SYSTEM_HOOKS];\n    \/\/ \u5f53\u524d\u8fd0\u884c\u5173\u95ed\u94a9\u5b50\u7684\u94a9\u5b50\u7684\u7d22\u5f15\n    private static int currentRunningHook = 0;\n    \/* \u524d\u9762\u7684\u9759\u6001\u5b57\u6bb5\u7531\u8fd9\u4e2a\u9501\u4fdd\u62a4 *\/\n    private static class Lock { };\n    private static Object lock = new Lock();\n \n    \/* \u4e3anative halt\u65b9\u6cd5\u63d0\u4f9b\u9501\u5bf9\u8c61 *\/\n    private static Object haltLock = new Lock();\n \n    static void add(int slot, boolean registerShutdownInProgress, Runnable hook) {\n        synchronized (lock) {\n            if (hooks[slot] != null)\n                throw new InternalError(&quot;Shutdown hook at slot &quot; + slot + &quot; already registered&quot;);\n \n            if (!registerShutdownInProgress) {\/\/\u6267\u884cshutdown\u8fc7\u7a0b\u4e2d\u4e0d\u6dfb\u52a0hook\n                if (state &gt; RUNNING)\/\/\u5982\u679c\u5df2\u7ecf\u5728\u6267\u884cshutdown\u64cd\u4f5c\u4e0d\u80fd\u6dfb\u52a0hook\n                    throw new IllegalStateException(&quot;Shutdown in progress&quot;);\n            } else {\/\/\u5982\u679chooks\u5df2\u7ecf\u6267\u884c\u5b8c\u6bd5\u4e0d\u80fd\u518d\u6dfb\u52a0hook\u3002\u5982\u679c\u6b63\u5728\u6267\u884chooks\u65f6\uff0c\u6dfb\u52a0\u7684\u69fd\u70b9\u5c0f\u4e8e\u5f53\u524d\u6267\u884c\u7684\u69fd\u70b9\u4f4d\u7f6e\u4e5f\u4e0d\u80fd\u6dfb\u52a0\n                if (state &gt; HOOKS || (state == HOOKS &amp;&amp; slot &lt;= currentRunningHook))\n                    throw new IllegalStateException(&quot;Shutdown in progress&quot;);\n            }\n \n            hooks[slot] = hook;\n        }\n    }\n    \/* \u6267\u884c\u6240\u6709\u6ce8\u518c\u7684hooks\n     *\/\n    private static void runHooks() {\n        for (int i=0; i &lt; MAX_SYSTEM_HOOKS; i++) {\n            try {\n                Runnable hook;\n                synchronized (lock) {\n                    \/\/ acquire the lock to make sure the hook registered during\n                    \/\/ shutdown is visible here.\n                    currentRunningHook = i;\n                    hook = hooks[i];\n                }\n                if (hook != null) hook.run();\n            } catch(Throwable t) {\n                if (t instanceof ThreadDeath) {\n                    ThreadDeath td = (ThreadDeath)t;\n                    throw td;\n                }\n            }\n        }\n    }\n    \/* \u5173\u95edJVM\u7684\u64cd\u4f5c\n     *\/\n    static void halt(int status) {\n        synchronized (haltLock) {\n            halt0(status);\n        }\n    }\n    \/\/JNI\u65b9\u6cd5\n    static native void halt0(int status);\n    \/\/ shutdown\u7684\u6267\u884c\u987a\u5e8f\uff1arunHooks &gt; runFinalizersOnExit\n    private static void sequence() {\n        synchronized (lock) {\n            \/* Guard against the possibility of a daemon thread invoking exit\n             * after DestroyJavaVM initiates the shutdown sequence\n             *\/\n            if (state != HOOKS) return;\n        }\n        runHooks();\n        boolean rfoe;\n        synchronized (lock) {\n            state = FINALIZERS;\n            rfoe = runFinalizersOnExit;\n        }\n        if (rfoe) runAllFinalizers();\n    }\n    \/\/Runtime.exit\u65f6\u6267\u884c\uff0crunHooks &gt; runFinalizersOnExit &gt; halt\n    static void exit(int status) {\n        boolean runMoreFinalizers = false;\n        synchronized (lock) {\n            if (status != 0) runFinalizersOnExit = false;\n            switch (state) {\n            case RUNNING:       \/* Initiate shutdown *\/\n                state = HOOKS;\n                break;\n            case HOOKS:         \/* Stall and halt *\/\n                break;\n            case FINALIZERS:\n                if (status != 0) {\n                    \/* Halt immediately on nonzero status *\/\n                    halt(status);\n                } else {\n                    \/* Compatibility with old behavior:\n                     * Run more finalizers and then halt\n                     *\/\n                    runMoreFinalizers = runFinalizersOnExit;\n                }\n                break;\n            }\n        }\n        if (runMoreFinalizers) {\n            runAllFinalizers();\n            halt(status);\n        }\n        synchronized (Shutdown.class) {\n            \/* Synchronize on the class object, causing any other thread\n             * that attempts to initiate shutdown to stall indefinitely\n             *\/\n            sequence();\n            halt(status);\n        }\n    }\n    \/\/shutdown\u64cd\u4f5c\uff0c\u4e0eexit\u4e0d\u540c\u7684\u662f\u4e0d\u505ahalt\u64cd\u4f5c(\u5173\u95edJVM)\n    static void shutdown() {\n        synchronized (lock) {\n            switch (state) {\n            case RUNNING:       \/* Initiate shutdown *\/\n                state = HOOKS;\n                break;\n            case HOOKS:         \/* Stall and then return *\/\n            case FINALIZERS:\n                break;\n            }\n        }\n        synchronized (Shutdown.class) {\n            sequence();\n        }\n    }\n}<\/code><\/pre>\n<h3>spring 3.2.12<\/h3>\n<p>\u5728spring\u4e2d\u901a\u8fc7<code>ContextClosedEvent<\/code>\u4e8b\u4ef6\u6765\u89e6\u53d1\u4e00\u4e9b\u52a8\u4f5c\uff08\u53ef\u4ee5\u62d3\u5c55\uff09\uff0c\u4e3b\u8981\u901a\u8fc7<code>LifecycleProcessor.onClose<\/code>\u6765\u505a<code>stopBeans<\/code>\u3002\u7531\u6b64\u53ef\u89c1spring\u4e5f\u57fa\u4e8ejvm\u505a\u4e86\u62d3\u5c55\u3002<\/p>\n<p>\u63a8\u8350\u4e00\u4e2a\u5f00\u6e90\u514d\u8d39\u7684 Spring Boot \u6700\u5168\u6559\u7a0b\uff1a<\/p>\n<blockquote><p><a href=\"https:\/\/link.segmentfault.com\/?enc=X5iQPfN%2Bvi%2BYVrmAGlTmLA%3D%3D.X048V9StFZ7kuOHY78HZ6fyxycNXGULnj3HdMMLq42ugyjFISTODElIKU3v3e46foIHClZ06OEz8wqMmdDUpQw%3D%3D\" rel=\"nofollow\">https:\/\/github.com\/javastacks\/spring-boot-best-practice<\/a><\/p><\/blockquote>\n<pre><code>public abstract class AbstractApplicationContext extends DefaultResourceLoader {\n public void registerShutdownHook() {\n  if (this.shutdownHook == null) {\n   \/\/ No shutdown hook registered yet.\n   this.shutdownHook = new Thread() {\n    @Override\n    public void run() {\n     doClose();\n    }\n   };\n   Runtime.getRuntime().addShutdownHook(this.shutdownHook);\n  }\n }\n protected void doClose() {\n  boolean actuallyClose;\n  synchronized (this.activeMonitor) {\n   actuallyClose = this.active &amp;&amp; !this.closed;\n   this.closed = true;\n  }\n \n  if (actuallyClose) {\n   if (logger.isInfoEnabled()) {\n    logger.info(&quot;Closing &quot; + this);\n   }\n \n   LiveBeansView.unregisterApplicationContext(this);\n \n   try {\n    \/\/\u53d1\u5e03\u5e94\u7528\u5185\u7684\u5173\u95ed\u4e8b\u4ef6\n    publishEvent(new ContextClosedEvent(this));\n   }\n   catch (Throwable ex) {\n    logger.warn(&quot;Exception thrown from ApplicationListener handling ContextClosedEvent&quot;, ex);\n   }\n \n   \/\/ \u505c\u6b62\u6240\u6709\u7684Lifecycle beans.\n   try {\n    getLifecycleProcessor().onClose();\n   }\n   catch (Throwable ex) {\n    logger.warn(&quot;Exception thrown from LifecycleProcessor on context close&quot;, ex);\n   }\n \n   \/\/ \u9500\u6bc1spring \u7684 BeanFactory\u53ef\u80fd\u4f1a\u7f13\u5b58\u5355\u4f8b\u7684 Bean.\n   destroyBeans();\n \n   \/\/ \u5173\u95ed\u5f53\u524d\u5e94\u7528\u4e0a\u4e0b\u6587\uff08BeanFactory\uff09\n   closeBeanFactory();\n \n   \/\/ \u6267\u884c\u5b50\u7c7b\u7684\u5173\u95ed\u903b\u8f91\n   onClose();\n \n   synchronized (this.activeMonitor) {\n    this.active = false;\n   }\n  }\n } \n}\npublic interface LifecycleProcessor extends Lifecycle {\n \/**\n  * Notification of context refresh, e.g. for auto-starting components.\n  *\/\n void onRefresh();\n \n \/**\n  * Notification of context close phase, e.g. for auto-stopping components.\n  *\/\n void onClose();\n}<\/code><\/pre>\n<h3>spring boot<\/h3>\n<p>\u5230\u8fd9\u91cc\u5c31\u8fdb\u5165\u91cd\u70b9\u4e86\uff0cspring boot\u4e2d\u6709<code>spring-boot-starter-actuator<\/code> \u6a21\u5757\u63d0\u4f9b\u4e86\u4e00\u4e2a restful \u63a5\u53e3\uff0c\u7528\u4e8e\u4f18\u96c5\u505c\u673a\u3002\u6267\u884c\u8bf7\u6c42 <code>curl -X POST http:\/\/127.0.0.1:8088\/shutdown<\/code> \uff0c\u5f85\u5173\u95ed\u6210\u529f\u5219\u8fd4\u56de\u63d0\u793a\u3002<\/p>\n<p>Spring Boot \u57fa\u7840\u5c31\u4e0d\u4ecb\u7ecd\u4e86\uff0c\u63a8\u8350\u770b\u8fd9\u4e2a\u514d\u8d39\u6559\u7a0b\uff1a<\/p>\n<blockquote>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=8IHaaBkLyi2SlIFgAg7vlg%3D%3D.RSvO3K7S4O1aBcwQENDI7TbBluEyxAf358xoAZWOhjUQgbSbylM8%2B1qE3CpsBbDThrighd5VMhFSqGYvYfnSzg%3D%3D\" rel=\"nofollow\">https:\/\/github.com\/javastacks\/spring-boot-best-practice<\/a><\/p>\n<p>\u6ce8\uff1a\u7ebf\u4e0a\u73af\u5883\u8be5url\u9700\u8981\u8bbe\u7f6e\u6743\u9650\uff0c\u53ef\u914d\u5408 spring-security\u4f7f\u7528\u6216\u5728nginx\u4e2d\u9650\u5236\u5185\u7f51\u8bbf\u95ee<\/p>\n<\/blockquote>\n<pre><code>#\u542f\u7528shutdown\nendpoints.shutdown.enabled=true\n#\u7981\u7528\u5bc6\u7801\u9a8c\u8bc1\nendpoints.shutdown.sensitive=false\n#\u53ef\u7edf\u4e00\u6307\u5b9a\u6240\u6709endpoints\u7684\u8def\u5f84\nmanagement.context-path=\/manage\n#\u6307\u5b9a\u7ba1\u7406\u7aef\u53e3\u548cIP\nmanagement.port=8088\nmanagement.address=127.0.0.1\n\n#\u5f00\u542fshutdown\u7684\u5b89\u5168\u9a8c\u8bc1\uff08spring-security\uff09\nendpoints.shutdown.sensitive=true\n#\u9a8c\u8bc1\u7528\u6237\u540d\nsecurity.user.name=admin\n#\u9a8c\u8bc1\u5bc6\u7801\nsecurity.user.password=secret\n#\u89d2\u8272\nmanagement.security.role=SUPERUSER<\/code><\/pre>\n<p>spring boot\u7684<code>shutdown<\/code>\u539f\u7406\u4e5f\u4e0d\u590d\u6742\uff0c\u5176\u5b9e\u8fd8\u662f\u901a\u8fc7\u8c03\u7528<code>AbstractApplicationContext.close<\/code>\u5b9e\u73b0\u7684\u3002<\/p>\n<pre><code>@ConfigurationProperties(\n    prefix = &quot;endpoints.shutdown&quot;\n)\npublic class ShutdownMvcEndpoint extends EndpointMvcAdapter {\n    public ShutdownMvcEndpoint(ShutdownEndpoint delegate) {\n        super(delegate);\n    }\n    \/\/post\u8bf7\u6c42\n    @PostMapping(\n        produces = {&quot;application\/vnd.spring-boot.actuator.v1+json&quot;, &quot;application\/json&quot;}\n    )\n    @ResponseBody\n    public Object invoke() {\n        return !this.getDelegate().isEnabled() ? new ResponseEntity(Collections.singletonMap(&quot;message&quot;, &quot;This endpoint is disabled&quot;), HttpStatus.NOT_FOUND) : super.invoke();\n    }\n}\n@ConfigurationProperties(\n    prefix = &quot;endpoints.shutdown&quot;\n)\npublic class ShutdownEndpoint extends AbstractEndpoint&lt;Map&lt;String, Object&gt;&gt; implements ApplicationContextAware {\n    private static final Map&lt;String, Object&gt; NO_CONTEXT_MESSAGE = Collections.unmodifiableMap(Collections.singletonMap(&quot;message&quot;, &quot;No context to shutdown.&quot;));\n    private static final Map&lt;String, Object&gt; SHUTDOWN_MESSAGE = Collections.unmodifiableMap(Collections.singletonMap(&quot;message&quot;, &quot;Shutting down, bye...&quot;));\n    private ConfigurableApplicationContext context;\n \n    public ShutdownEndpoint() {\n        super(&quot;shutdown&quot;, true, false);\n    }\n    \/\/\u6267\u884c\u5173\u95ed\n    public Map&lt;String, Object&gt; invoke() {\n        if (this.context == null) {\n            return NO_CONTEXT_MESSAGE;\n        } else {\n            boolean var6 = false;\n \n            Map var1;\n \n            class NamelessClass_1 implements Runnable {\n                NamelessClass_1() {\n                }\n \n                public void run() {\n                    try {\n                        Thread.sleep(500L);\n                    } catch (InterruptedException var2) {\n                        Thread.currentThread().interrupt();\n                    }\n                    \/\/\u8fd9\u4e2a\u8c03\u7528\u7684\u5c31\u662fAbstractApplicationContext.close\n                    ShutdownEndpoint.this.context.close();\n                }\n            }\n \n            try {\n                var6 = true;\n                var1 = SHUTDOWN_MESSAGE;\n                var6 = false;\n            } finally {\n                if (var6) {\n                    Thread thread = new Thread(new NamelessClass_1());\n                    thread.setContextClassLoader(this.getClass().getClassLoader());\n                    thread.start();\n                }\n            }\n \n            Thread thread = new Thread(new NamelessClass_1());\n            thread.setContextClassLoader(this.getClass().getClassLoader());\n            thread.start();\n            return var1;\n        }\n    }\n}<\/code><\/pre>\n<p>\u7248\u6743\u58f0\u660e\uff1a\u672c\u6587\u4e3aCSDN\u535a\u4e3b\u300c\u5e03\u9053\u300d\u7684\u539f\u521b\u6587\u7ae0\uff0c\u9075\u5faaCC 4.0 BY-SA\u7248\u6743\u534f\u8bae\uff0c\u8f6c\u8f7d\u8bf7\u9644\u4e0a\u539f\u6587\u51fa\u5904\u94fe\u63a5\u53ca\u672c\u58f0\u660e\u3002\u539f\u6587\u94fe\u63a5\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=W80EPPj%2B6x5HlYq000Ivxg%3D%3D.c%2FtS%2FAarrPOnbe2NCXg7vChxCn2LyOSM%2F3QWj0StDwxV1D1kd5ALObl7EFZNZd3%2FKQcWp3w5J4BRLC8A4qHVFw%3D%3D\" rel=\"nofollow\">https:\/\/blog.csdn.net\/alex_xf&#8230;<\/a><\/p>\n<p><strong>\u8fd1\u671f\u70ed\u6587\u63a8\u8350\uff1a<\/strong><\/p>\n<p>1.<a href=\"https:\/\/link.segmentfault.com\/?enc=KnR67ZGLkHZd0Qm3UN%2BiyQ%3D%3D.PQWPpQgNCGeELjmbXP1vKkD%2FHdYBbf%2Bn3ozPK8lb44k%3D\" rel=\"nofollow\">1,000+ \u9053 Java\u9762\u8bd5\u9898\u53ca\u7b54\u6848\u6574\u7406(2022\u6700\u65b0\u7248)<\/a><\/p>\n<p>2.<a href=\"https:\/\/link.segmentfault.com\/?enc=6XLXes0iEwAZNGj3dDvJpQ%3D%3D.Im%2BxiPA5FZPlsUnNBC4ryh28SN6iNUQ%2F%2Bb6LzYQG5rOnntyz0Mqa6pP%2BXCunP8NPMHTN0eAB1l9tCxCjfdHILA%3D%3D\" rel=\"nofollow\">\u52b2\u7206\uff01Java \u534f\u7a0b\u8981\u6765\u4e86\u3002\u3002\u3002<\/a><\/p>\n<p>3.<a href=\"https:\/\/link.segmentfault.com\/?enc=2AETD9CCaKnL02XHeQm92w%3D%3D.sflTPTeuJvsUIV1lXSVmxdFff5rg6v%2FaRcYZjxQZvy05Ej%2FWOYRIB4BpQCyDcqgG\" rel=\"nofollow\">Spring Boot 2.x \u6559\u7a0b\uff0c\u592a\u5168\u4e86\uff01<\/a><\/p>\n<p>4.<a href=\"https:\/\/link.segmentfault.com\/?enc=XlhShxiOYGSRUHyc9Kds6Q%3D%3D.%2B2tpV3NO3BhlxNldb11NInJ%2BcOzdx8eRNRbz3ZTJDNsllOJp%2BtgvqBbyyFYaoU1VU2KdDwg9IDTqQegJzQQkqw%3D%3D\" rel=\"nofollow\">\u522b\u518d\u5199\u6ee1\u5c4f\u7684\u7206\u7206\u7206\u70b8\u7c7b\u4e86\uff0c\u8bd5\u8bd5\u88c5\u9970\u5668\u6a21\u5f0f\uff0c\u8fd9\u624d\u662f\u4f18\u96c5\u7684\u65b9\u5f0f\uff01\uff01<\/a><\/p>\n<p>5.<a href=\"https:\/\/link.segmentfault.com\/?enc=SWsT%2BRGdw67lmliI1r4jGg%3D%3D.ZW9TKjpzSBS1kzaIlNpoRSbjT6hisc3DMldOIt8qpX7BXyVHjj%2BW%2FWfPUYXDk9rBma7eCMkDON2dzsWANbgykOrID3OGOvxLbcuagp0sxc8%3D\" rel=\"nofollow\">\u300aJava\u5f00\u53d1\u624b\u518c\uff08\u5d69\u5c71\u7248\uff09\u300b\u6700\u65b0\u53d1\u5e03\uff0c\u901f\u901f\u4e0b\u8f7d\uff01<\/a><\/p>\n<p>\u89c9\u5f97\u4e0d\u9519\uff0c\u522b\u5fd8\u4e86\u968f\u624b\u70b9\u8d5e+\u8f6c\u53d1\u54e6\uff01<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000042667910\">https:\/\/segmentfault.com\/a\/1190000042667910<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u518d\u8c08\u4e3a\u4e86\u63d0\u9192\u660e\u77e5\u6545\u72af\uff08\u5728\u4e00\u5751\u91cc\u8fed\u5012\u4e24\u6b21\u4e0d\u662f\u4e0d\u591a\u89c1\uff09\uff0c\u7531\u4e8e\u4e1a\u52a1\u7cfb\u7edf\u4e2d\u5927\u91cf\u4f7f\u7528\u4e86spring Boot embed [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-10006712","post","type-post","status-publish","format-standard","hentry"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006712","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10006712"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006712\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10006712"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10006712"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10006712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}