java ²¶×½ÐźÅ(linuxϵÄkill,ctrl+c)
import sun.misc.Signal;
import sun.misc.SignalHandler;
/***
* javaÐźŴ¦Àídemo
* @author jiang_qh
*
*/
public class SignalHandlerExample implements SignalHandler{
private SignalHandler oldHandler;
public void handle(Signal signal) {
System.out.println("Signal handler called for signal "
+ signal);
try {
signalAction(signal);
// Chain back to previous handler, if one exists
if (oldHandler != SIG_DFL && oldHandler != SIG_IGN) {
oldHandler.handle(signal);
}
} catch (Exception e) {
System.out.println("handle|Signal handler"
+"failed, reason " + e.getMessage());
e.printStackTrace();
}
}
public void signalAction(Signal signal) {
System.out.println("Handling " + signal.getName());
System.out.println("Just sleep for 5 seconds.");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
System.out.println("Interrupted: "
+ e.getMessage());
}
}
public static SignalHandler install(String signalName) {
Signal diagSignal = new Signal(signalName);
SignalHandlerExample instance = new SignalHandlerExample();
instance.oldHandler = Signal.handle(diagSignal, instance);
return instance;
}
public static void main(String[] args) {
//killÃüÁî
SignalHandlerExample.install("TERM");
//ctrl+cÃüÁî
SignalHandlerExample.install("INT");
System.out.println("Signal handling example.");
try {
Thread.sleep(50000);
} catch (InterruptedException e) {
System.out.println("Interrupted: " + e.getMessage());
}
}
}
ÔÚlinuxÉÏÔËÐиóÌÐò¡£È»ºókillµôÆäpid£¬´òÓ¡£º
Signal handling example.
Signal handler called for signal SIGTERM
Handling TERM
Just sleep for 5 seconds.
[dispatch@loc
Ïà¹ØÎĵµ£º
Ó°ÏìÄ£¿éÉè¼ÆºÃÓ뻵µÄÒ»¸öÖØÒªÒòËؾÍÊÇÕâ¸öÄ£¿éÊÇ·ñÒþ²ØËüµÄÄÚ²¿Êý¾ÝºÍÆäËûһЩʵÏÖϸ½Ú¡£ ÐÅÏ¢Òþ²ØµÄºÃ´¦£º·½±ã¶ÀÁ¢¿ª·¢£¬²âÊÔ£¬ÓÅ»¯£¬Ê¹Óã¬Àí½âºÍÐ޸ġ£Äܹ»Ìá¸ßϵͳ¿ª·¢ËÙ£¨ÒòΪ¸÷Ä£¿é¿ÉÒÔ²¢Ðпª·¢£©£¬Ò²ÄÜÒ×ÓÚά»¤ºÍµ÷ÊÔ£¬Ò²ÄܼõÉÙϵͳ¹¹½¨µÄ·çÏÕ¡£ ......
JavaµÄÒ»¸öÖØÒªÓŵã¾ÍÊÇͨ¹ýÀ¬»øÊÕ¼¯Æ÷(Garbage Collection£¬GC)×Ô¶¯¹ÜÀíÄÚ´æµÄ»ØÊÕ£¬³ÌÐòÔ±²»ÐèҪͨ¹ýµ÷Óú¯ÊýÀ´ÊÍ·ÅÄÚ´æ¡£Òò´Ë£¬ºÜ¶à³ÌÐòÔ±ÈÏΪJava²»´æÔÚÄÚ´æй©ÎÊÌ⣬»òÕßÈÏΪ¼´Ê¹ÓÐÄÚ´æй©Ҳ²»ÊdzÌÐòµÄÔðÈΣ¬¶øÊÇGC»òJVMµÄÎÊÌâ¡£Æäʵ£¬ÕâÖÖÏë·¨ÊDz»ÕýÈ·µÄ£¬ÒòΪJavaÒ²´æÔÚÄÚ´æй¶£¬µ«ËüµÄ±íÏÖÓëC++²»Í¬¡£
ÎÊÌâµÄÌá ......
·ÏÁË¡£2ÄêûÕý¾ÓùýJavaÁË¡£ÎªÁË°ïÅóÓÑæ±ØÐëÈ«²¿¼ñÆðÀ´¡£BT¼Æ»®±»ÆÈÔÝÍ£¡£
»¹ÊǺÃÄÔ×Ó²»ÈçÀñÊÍ·¡£
¼ÇÏÂÀ´£º
Java»·¾³±äÁ¿ÉèÖãº
http://blog.csdn.net/aneka/archive/2008/09/19/2948209.aspx
ѧϰ Java ¿ª·¢µÄµÚÒ»²½¾ÍÊǹ¹½¨¿ª·¢»·¾³£¬ÏÂÃæÒÔ JDK6.0 ÔÚ Windows XP ÉϵݲװÅäÖÃΪÀýÀ´½²Êö£º
µÚÒ»²½£ºÏÂÔØ JDK
´ ......
TimerλÓÚjava.utilÏÂÃ棬һ°ã½ÐËûjava¼ÆʱÆ÷¡£
javaAPIµÄ½âÊÍÈçÏÂ:
Ò»ÖÖÏß³ÌÉèÊ©£¬ÓÃÓÚ°²ÅÅÒÔºóÔÚºǫ́Ïß³ÌÖÐÖ´ÐеÄÈÎÎñ¡£¿É°²ÅÅÈÎÎñÖ´ÐÐÒ»´Î£¬»òÕ߶¨ÆÚÖظ´Ö´ÐС£
ÏÈÀ´¿´¿´Ð§¹û£º
1.Éè¼Æ¼ÆʱÆ÷
import java.io.IOException;
import java.util.Calendar;
import java.util.Timer;
public class TimerTest {
......