Java Timer ¶ÔÏó´´½¨ºóʹÓÃTimer¸ü¸ÄÆäÊôÐÔ!!!
Ê×ÏÈÀ´¸ö¼òµ¥ÄǵÄʵÀý:
package cn.vicky;
import java.util.Timer;
import java.util.TimerTask;
public class MyTimer {
private int i = 1;
private void change(long time){
System.out.println("one : " + i);
final Timer timer = new Timer();
timer.schedule(new TimerTask(){
@Override
public void run() {
System.out.println("run " + i++);
if (i != 5) {
timer.cancel();
}
}
}, 10000,1);
System.out.println("two : " + i);
}
public static void main(String[] args) {
MyTimer mytimer = new MyTimer();
mytimer.change(0);
}
}
ÎÒÃÇÒÔÒ»¸öʵÀý˼¿¼,³µÕ¾,ÿÁ¾³µÖ»ÄÜÍ£¿¿10·ÖÖӾͱØÐë³öÕ¾.´«Í³·½Ê½,ÎÒÃÇÊÇÒÔ³µÕ¾Îªµ¥Î»,ͨ¹ý¶àÏß³ÌÀ´¿ØÖÆÿÁ¾³µµÄ³öÕ¾Çé¿ö!
package cn.vicky;
import java.util.Date;
/**
*
* @author Vicky
* ¹«½»Æû³µ
*/
public class Bus {
private String name = "";
private boolean inStation = true;
/**
* ¹«½»Æû³µÔÚ³µÕ¾ÖÐÖ»¿ÉÄÜ´ô10·ÖÖÓ,È»ºó¹«½»¾Í¿ª×ß,Ïà¶ÔÓÚ¹«½»³µÕ¾,¹«½»10·ÖÖÓºó¾ÍΪ¿Õ!
*/
public Bus(String carName) {
this.name = carName;
System.out.println(new Date() + " : a car["+ name +"] into the bus station !");
}
public void setInStation(boolean inStation) {
this.inStation = inStation;
}
public boolean isInStation() {
return inStation;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final Bus other = (Bus) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
@Override
public String toString() {
return "Bus [" + name + "] :: " + (inSta
Ïà¹ØÎĵµ£º
The goal for this chapter is to introduce you to Java's native methods. If you are new to Java, you may not know what native methods are, and even if you are an experienced Java developer, you may not have had a reason to learn more about native methods. At the conclusion of this chapter you should ......
Ò»¡¢Ç°ÑÔ
±¾Îļٶ¨ÄãÓÐÒ»¶¨µÄJ2EE¿ª·¢¾Ñ飬Õâ¸ö½Ì³ÌûÓйý¶àµÄÉæ¼°»ù´¡ÖªÊ¶ºÍ¿ª·¢Ï¸½Ú¡£Èç¹ûÔÚÔĶÁ¹ý³Ì³öÓÐʲôÎÊÌ⣬»¹ÇëÓëÎÒÁªÏµ½»Á÷¡£
Èç¹ûʹÓÃGOOGLE¡¢BAIDUµÈËÑË÷¹¤¾ß£¬ËÑË÷WebServiceµÄÏà¹Ø֪ʶ£¬¿ÉÒԲ鵽N¶àµÄÍøÒ³£¬ÎÒ¾ÍÊÇͨ¹ýÕâЩÍøÒ³µÄѧϰ£¬Öð½¥ÕÆÎ ......
ÇëÌṩһ¸ö¶ÔiµÄÉùÃ÷£¬½«ÏÂÃæµÄÑ»·×ª±äΪһ¸öÎÞÏÞÑ»·£º
while (i != 0) {
i >>>= 1;
}
»ØÏëһϣ¬>>>=ÊǶÔÓ¦ÓÚÎÞ·ûºÅÓÒÒƲÙ×÷·ûµÄ¸³Öµ²Ù×÷·û¡£0±»´Ó×óÒÆÈëµ½ÓÉÒÆλ²Ù×÷¶ø¿Õ³öÀ´µÄλÉÏ£¬¼´Ê¹±»ÒÆλµÄ¸ºÊýÒ²ÊÇÈç´Ë¡£
Õâ¸öÑ»·±ÈÇ°ÃæÈý¸öÑ»·ÒªÉÔ΢¸´ÔÓÒ»µã£¬ÒòΪÆäÑ»·Ìå·Ç¿Õ¡£ÔÚÆäÑ»·ÌâÖУ¬ ......
ÇëÌṩһ¸ö¶ÔiµÄÉùÃ÷£¬½«ÏÂÃæµÄÑ»·×ª±äΪһ¸öÎÞÏÞÑ»·¡£Õâ¸öÑ»·²»ÐèҪʹÓÃÈκÎ5.0°æµÄÌØÐÔ£º
while (i != 0 && i == -i) {
}
ÕâÈÔÈ»ÊÇÒ»¸öÑ»·¡£ÔÚ²¼¶û±í´ïʽ(i != 0 && i == -i)ÖУ¬Ò»Ôª¼õºÅ²Ù×÷·û×÷ÓÃÓÚi£¬ÕâÒâζ×ÅËüµÄÀàÐͱØÐëÊÇÊý×ÖÐ͵ģºÒ»Ôª¼õºÅ²Ù×÷·û×÷ÓÃÓÚÒ»¸ö·ÇÊý×ÖÐͲÙ×÷ÊýÊÇ·Ç·¨µÄ¡£Òò´Ë£ ......
ÏÂÃæÕâ¸ö¿ÉÁ¯µÄС³ÌÐò²¢²»ÄܺܺõØ×ö³öÆä×Ô¼ºµÄ¾ö¶¨¡£ËüµÄdecision·½·¨½«·µ»Øtrue£¬µ«ÊÇËü»¹·µ»ØÁËfalse¡£ÄÇô£¬Ëüµ½µ×´òÓ¡µÄÊÇʲôÄØ£¿ÉõÖÁ£¬ËüÊǺϷ¨µÄÂð£¿
public class Indecisive {
public static void main(String[] args) {
System.out.println(decision());
}
static boolean decision( ......