001    /*
002     * LAPIS lightweight structured text processing system
003     *
004     * Copyright (C) 1998-2002 Carnegie Mellon University,
005     * Copyright (C) 2003 Massachusetts Institute of Technology.
006     * All rights reserved.
007     *
008     * This library is free software; you can redistribute it
009     * and/or modify it under the terms of the GNU General
010     * Public License as published by the Free Software
011     * Foundation, version 2.
012     *
013     * LAPIS homepage: http://graphics.lcs.mit.edu/lapis/
014     */
015    
016    
017    package lapisx.util;
018    
019    public abstract class Thr {
020        /**
021          * Test whether the current thread has been interrupted with 
022          * Thread.interrupt().  If so, a ThreadDeath exception is thrown
023          * to kill it cleanly.  If a background thread
024          * calls check() periodically, then Thread.interrupt() will
025          * kill it cleanly and safely at the next check() call.  Catch ThreadDeath
026          * or use a try-finally construct if your background thread needs to do 
027          * any resource cleanup.
028          *
029          * @exception ThreadDeath if and only if 
030          * Thread.currentThread().isInterrupted() is true.
031          */
032        public static void check () throws ThreadDeath {
033            if (Thread.currentThread ().isInterrupted ())
034                throw new ThreadDeath ();
035        }
036    }