Skip to content

Add hook mechanism to quit command #518

Closed

Description

@guang384

Many times, I think it is not the best choice to re implement the exit command by inherit Quit and implement Quit.Command.

In most cases, I just want to perform some cleanup when issuing the exit command. I suggest that you can consider referring to the shutdown hook method of the runtime.

Runtime.getRuntime().addShutdownHook( () -> System.out.println("I'm shutdown hook...") );

Can you consider adding a "QuitCommandHook" mechanism instead of always rewriting the quit class to perform exit cleanup logic. The way envisaged is similar to:
Quit.addCommandHook( () -> System.out.println("I'm shutdown hook...") );

If possible, I would be happy to submit a PR on this issue.

Activity

  1. jvalkeal commented on Aug 30, 2022

    @jvalkeal
    Contributor

    Have you thought about using any other means on your disposal to clean when application is going to exit? Bean destroy methods, application events from framework/boot etc?

    I think jline has its own shutdown hook and spring has one as well in its core so it's a bit bad practice to add more of those as afaik hooks cannot be ordered.

  2. locked and limited conversation to collaborators on Aug 30, 2022
  3. converted this issue into a discussion #519 on Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions