Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

JAVA¶¨Ê±Æ÷ Timer+TimerTask

     ±¾ÎÄÊ×ÏÈÉè¼ÆÒ»¸öµ¥´Î¶¨Ê±Æ÷Timer+TimerTask£¬È»ºóÔٴλù´¡ÉÏÉè¼ÆÒ»¸öÑ­»·¶¨Ê±Æ÷¡£
     ÎÒ½«°Ñ java.util.Timer ºÍ java.util.TimerTask ͳ³ÆÎª Java ¼ÆÊ±Æ÷¿ò¼Ü£¬ËüÃÇʹ³ÌÐòÔ±¿ÉÒÔºÜÈÝÒ׵ؼƻ®¼òµ¥µÄÈÎÎñ£¨×¢ÒâÕâЩÀàÒ²¿ÉÓÃÓÚ J2ME ÖУ©¡£²»¹ý£¬Java ¼ÆÊ±Æ÷¿ò¼ÜûÓÐ×ã¹»µÄÄÜÁ¦À´Âú×ãÐí¶àÓ¦ÓóÌÐòµÄ¼Æ»®ÒªÇó¡£ÉõÖÁÒ»ÏîÐèÒªÔÚÿÌìͬһʱ¼äÖØ¸´Ö´ÐеÄÈÎÎñ£¬Ò²²»ÄÜÖ±½ÓʹÓà Timer À´¼Æ»®£¬Òò´ËÎÒÃǽ«ÔÙTimer+TimerTaskµÄ»ù´¡ÉÏÉè¼ÆÒ»¸öͨÓõÄÑ­»·¶¨Ê±Æ÷£¬ÕâÀï³ÆÖ®Îª¼Æ»®¿ò¼Ü£¬´Ó¶øÔÊÐí¸üÁé»îµÄ¼Æ»®ÈÎÎñ¡£Õâ¸ö¿ò¼Ü·Ç³£¼òµ¥ ¨D¨D Ëü°üÀ¨Á½¸öÀàºÍÒ»¸ö½Ó¿Ú ¨D¨D ²¢ÇÒÈÝÒ×ÕÆÎÕ¡£
Ò»¡¢¼Æ»®µ¥´ÎÈÎÎñ
     ÏëÏñÒ»¸öÖóµ°¼ÆÊ±Æ÷£¬ÔÚÊý·ÖÖÓÖ®ºó£¨Õâʱµ°ÖóºÃÁË£©Ëü»á·¢³öÉùÒôÌáÐÑÄú¡£Listing 1 ¹¹³ÉÁËÒ»¸ö¼òµ¥µÄÖóµ°¼ÆÊ±Æ÷µÄ»ù±¾½á¹¹£º
¡¾Listing 1£ºµ¥´Î¶¨Ê±Æ÷Timer+TimerTask¡¿
import java.util.Timer;
import java.util.TimerTask;
/********************************************************************
* µ¥´Î¼ÆÊ±Æ÷ Timer+TimerTask×éºÏ
* TimerÀàÊÇḬ̈߳²È«µÄ£º¶à¸öÏ߳̿ÉÒÔ¹²Ïíµ¥¸ö Timer ¶ÔÏó¶øÎÞÐè½øÐÐÍⲿͬ²½¡£
* Óëÿ¸öTimer¶ÔÏóÏà¶ÔÓ¦µÄÊǵ¥¸öºǫ́Ị̈߳¬ÓÃÓÚ˳ÐòµØÖ´ÐÐËùÓмÆÊ±Æ÷ÈÎÎñ¡£
*/
public class EggTimer {
private final Timer timer = new Timer();
private final int minutes;
public EggTimer(int minutes) {
this.minutes = minutes;
}
public void start() {
timer.schedule(new TimerTask() {
public void run() {
playSound();
timer.cancel();
}
private void playSound() {
System.out.println("Your egg is ready!");
}
}, minutes * 1000);
}
public static void main(String[] args) {
EggTimer eggTimer = new EggTimer(2);
eggTimer.start();
}
}
     EggTimer ÀàÓµÓÐÒ»¸ö Timer ʵÀý£¬ÓÃÓÚÌṩ±ØÒªµÄ¼Æ»®¡£Óà start() ·½·¨Æô¶¯Öóµ°¼ÆÊ±Æ÷ºó£¬Ëü¾Í¼Æ»®ÁËÒ»¸ö TimerTask £¬ÔÚÖ¸¶¨µÄ·ÖÖÓÊýÖ®ºóÖ´ÐС£Ê±¼äµ½ÁË£¬ Timer ¾ÍÔÚºǫ́µ÷Óà TimerTask µÄ start() ·½·¨£¬Õâ»áʹËü·¢³öÉùÒô¡£ÔÚÈ¡Ïû¼ÆÊ±Æ÷ºóÕâ¸öÓ¦ÓóÌÐò¾Í»áÖÐÖ¹¡£
¶þ¡¢¼Æ»®Öظ´Ö´ÐеÄÈÎÎñ
     ͨ¹ýÖ¸¶¨Ò»¸ö¹Ì¶¨µÄÖ´ÐÐÆµÂÊ»òÕ߹̶¨µÄÖ´ÐÐʱ¼ä¼ä¸ô£¬ Timer


Ïà¹ØÎĵµ£º

dzÎöJavaµÄ¡°¿Ë¡¡±·½·¨ תÌù

ZT:http://javahy.javaeye.com/blog/384871
¡¡¡¡JavaÓïÑÔµÄÒ»¸öÓŵã¾ÍÊÇÈ¡ÏûÁËÖ¸ÕëµÄ¸ÅÄµ«Ò²µ¼ÖÂÁËÐí¶à³ÌÐòÔ±ÔÚ±à³ÌÖг£³£ºöÂÔÁ˶ÔÏóÓëÒýÓõÄÇø±ð£¬±¾ÎÄ»áÊÔͼ³ÎÇåÕâÒ»¸ÅÄî¡£²¢ÇÒÓÉÓÚJava²»ÄÜͨ¹ý¼òµ¥µÄ¸³ÖµÀ´½â¾ö¶ÔÏó¸´ÖƵÄÎÊÌ⣬ÔÚ¿ª·¢¹ý³ÌÖУ¬Ò²³£³£ÒªÒªÓ¦ÓÃclone£¨£©·½·¨À´¸´ÖƶÔÏó¡£±¾ÎÄ»áÈÃÄãÁ˽âʲôÊÇÓ°×Óclone ......

һЩ³£¼ûJavaÒì³£¹éÀà(Ò»)

UnsupportedClassVersionError
¡¡¡¡²»Ö§³ÖµÄÀà°æ±¾´íÎó¡£µ±JavaÐéÄâ»úÊÔͼ´Ó¶Áȡij¸öÀàÎļþ£¬µ«ÊÇ·¢ÏÖ¸ÃÎļþµÄÖ÷¡¢´Î°æ±¾ºÅ²»±»µ±Ç°JavaÐéÄâ»úÖ§³ÖµÄʱºò£¬Å׳ö¸Ã´íÎó¡£
¡¡¡¡java.lang.VerifyError
¡¡¡¡ÑéÖ¤´íÎó¡£µ±ÑéÖ¤Æ÷¼ì²âµ½Ä³¸öÀàÎļþÖдæÔÚÄÚ²¿²»¼æÈÝ»òÕß°²È«ÎÊÌâʱÅ׳ö¸Ã´íÎó¡£
¡¡¡¡java.lang.VirtualMachineErr ......

һЩ³£¼ûJavaÒì³£¹éÀà(¶þ)

ËãÊõÒì³£ÀࣺArithmeticExecption
¡¡¡¡¿ÕÖ¸ÕëÒì³£ÀࣺNullPointerException
¡¡¡¡ÀàÐÍÇ¿ÖÆ×ª»»Òì³££ºClassCastException
¡¡¡¡Êý×鸺ϱêÒì³££ºNegativeArrayException
¡¡¡¡Êý×éϱêÔ½½çÒì³££ºArrayIndexOutOfBoundsException
¡¡¡¡Î¥±³°²È«Ô­ÔòÒì³££ºSecturityException
¡¡¡¡ÎļþÒѽáÊøÒì³££ºEOFException
¡¡¡¡ÎļþÎ´Õ ......

java servlet ÂÒÂë

javaдÎļþÂÒÂë
StringBuffer sb = new StringBuffer();
  sb.append("<table  border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"1\" bgcolor=\"b5d6e6\"");
  sb.append("<tr>");
  sb.append("<td bgcolor=\"#FFFFFE\" height=\"42\" colspan=\""+ (jsd ......

JAVA·´Éä»úÖÆ

JAVA·´Éä»úÖÆÊÇÔÚÔËÐÐ״̬ÖУ¬¶ÔÓÚÈÎÒâÒ»¸öÀ࣬¶¼Äܹ»ÖªµÀÕâ¸öÀàµÄËùÓÐÊôÐԺͷ½·¨£»¶ÔÓÚÈÎÒâÒ»¸ö¶ÔÏ󣬶¼Äܹ»µ÷ÓÃËüµÄÈÎÒâÒ»¸ö·½·¨£»ÕâÖÖ¶¯Ì¬»ñÈ¡µÄÐÅÏ¢ÒÔ¼°¶¯Ì¬µ÷ÓöÔÏóµÄ·½·¨µÄ¹¦ÄܳÆÎªjavaÓïÑԵķ´Éä»úÖÆ¡£
package mypakage;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ