001    /**
002     * 
003     * $Revision: 13085 $ $Date: 2008-02-06 18:27:24 +0100 (Mi, 06 Feb 2008) $
004     *
005     * This file is part of ** M y C o R e **
006     * Visit our homepage at http://www.mycore.de/ for details.
007     *
008     * This program is free software; you can use it, redistribute it
009     * and / or modify it under the terms of the GNU General Public License
010     * (GPL) as published by the Free Software Foundation; either version 2
011     * of the License or (at your option) any later version.
012     *
013     * This program is distributed in the hope that it will be useful, but
014     * WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016     * GNU General Public License for more details.
017     *
018     * You should have received a copy of the GNU General Public License
019     * along with this program, normally in the file license.txt.
020     * If not, write to the Free Software Foundation Inc.,
021     * 59 Temple Place - Suite 330, Boston, MA  02111-1307 USA
022     *
023     **/
024    package org.mycore.common.events;
025    
026    import org.apache.log4j.Logger;
027    
028    /**
029     * is a shutdown hook for the current <code>Runtime</code>.
030     * 
031     * This class registers itself as a shutdown hook to the JVM. 
032     * 
033     * There is no way to instanciate this class somehow. This will be done by MCRShutdownHandler.
034     * 
035     * @author Thomas Scheffler (yagee)
036     * @see java.lang.Runtime#addShutdownHook(java.lang.Thread)
037     * @see org.mycore.common.events.MCRShutdownHandler
038     * @since 1.3
039     */
040    public class MCRShutdownThread extends Thread {
041    
042        private static final Logger LOGGER = Logger.getLogger(MCRShutdownThread.class);
043    
044        private static final MCRShutdownThread SINGLETON = new MCRShutdownThread();
045    
046        private MCRShutdownThread() {
047            this.setName("MCR-exit");
048            LOGGER.info("adding MyCoRe ShutdownHook");
049            Runtime.getRuntime().addShutdownHook(this);
050        }
051    
052        static MCRShutdownThread getInstance() {
053            return SINGLETON;
054        }
055    
056        public void run() {
057            MCRShutdownHandler sh =MCRShutdownHandler.getInstance(); 
058            if(sh!=null) sh.shutDown();
059        }
060    }