java.lang.IllegalArgumentException: Hook previously registered

Spring JIRA | Torsten Krah | 5 years ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    Hi, i am using the SingletonBeanFactoryLocator to create my context (no webapp and no single main there, so i need to do it so). Its possible that many threads does call this method and they all get the same context. But registerShutdownHook fails for some threads, because its already registered. May it be possible to make this like refresh + close synchronized on the startupShutdown monitor to register only one hook. {noformat} /** * Context. * @param bfLocatorKey * @param parentContextKey * @return */ public static ApplicationContext getAppContext(String bfLocatorKey, String parentContextKey) { BeanFactoryLocator bfLocator = SingletonBeanFactoryLocator .getInstance(bfLocatorKey); BeanFactoryReference bfReference = bfLocator.useBeanFactory(parentContextKey); BeanFactory factory = bfReference.getFactory(); ConfigurableApplicationContext c = (ConfigurableApplicationContext) factory; c.registerShutdownHook(); return c; } {noformat} Exception is: {noformat} java.lang.IllegalArgumentException: Hook previously registered at java.lang.ApplicationShutdownHooks.add(ApplicationShutdownHooks.java:72) ~[na:1.7.0_147-icedtea] at java.lang.Runtime.addShutdownHook(Runtime.java:209) ~[na:1.7.0_147-icedtea] at org.springframework.context.support.AbstractApplicationContext.registerShutdownHook(AbstractApplicationContext.java:961) ~[org.springframework.context-3.1.1.RELEASE.jar:3.1.1.RELEASE] {noformat}

    Spring JIRA | 5 years ago | Torsten Krah
    java.lang.IllegalArgumentException: Hook previously registered
  2. 0

    Hi, i am using the SingletonBeanFactoryLocator to create my context (no webapp and no single main there, so i need to do it so). Its possible that many threads does call this method and they all get the same context. But registerShutdownHook fails for some threads, because its already registered. May it be possible to make this like refresh + close synchronized on the startupShutdown monitor to register only one hook. {noformat} /** * Context. * @param bfLocatorKey * @param parentContextKey * @return */ public static ApplicationContext getAppContext(String bfLocatorKey, String parentContextKey) { BeanFactoryLocator bfLocator = SingletonBeanFactoryLocator .getInstance(bfLocatorKey); BeanFactoryReference bfReference = bfLocator.useBeanFactory(parentContextKey); BeanFactory factory = bfReference.getFactory(); ConfigurableApplicationContext c = (ConfigurableApplicationContext) factory; c.registerShutdownHook(); return c; } {noformat} Exception is: {noformat} java.lang.IllegalArgumentException: Hook previously registered at java.lang.ApplicationShutdownHooks.add(ApplicationShutdownHooks.java:72) ~[na:1.7.0_147-icedtea] at java.lang.Runtime.addShutdownHook(Runtime.java:209) ~[na:1.7.0_147-icedtea] at org.springframework.context.support.AbstractApplicationContext.registerShutdownHook(AbstractApplicationContext.java:961) ~[org.springframework.context-3.1.1.RELEASE.jar:3.1.1.RELEASE] {noformat}

    Spring JIRA | 5 years ago | Torsten Krah
    java.lang.IllegalArgumentException: Hook previously registered
  3. 0

    Problem with Runtime.addShutdownHook when porting from Windows to HP-UX

    Google Groups | 2 decades ago | Jean-François Daune
    java.lang.IllegalArgumentException: Unknown signal: HUP
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Xrs option and shutdown hooks

    Oracle Community | 2 decades ago | 843798
    java.lang.IllegalArgumentException: Signal already used by VM: SIGINT
  6. 0

    addShutdownHook not working in HP-Unix

    Oracle Community | 2 decades ago | 807592
    java.lang.IllegalArgumentException: Unknown signal: HUP

  1. hoangtranwork 1 times, last 11 months ago

Root Cause Analysis

  1. java.lang.IllegalArgumentException

    Hook previously registered

    at java.lang.ApplicationShutdownHooks.add()
  2. Java RT
    Runtime.addShutdownHook
    1. java.lang.ApplicationShutdownHooks.add(ApplicationShutdownHooks.java:72)[na:1.7.0_147-icedtea]
    2. java.lang.Runtime.addShutdownHook(Runtime.java:209)[na:1.7.0_147-icedtea]
    2 frames
  3. Spring Context
    AbstractApplicationContext.registerShutdownHook
    1. org.springframework.context.support.AbstractApplicationContext.registerShutdownHook(AbstractApplicationContext.java:961)[org.springframework.context-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    1 frame