javaµÄ»Øµ÷¼¼Êõdz̸
ÎÒÃǾ³£»áÓÃSystem.currentTimeMillis()ÔÚʼþ¿ªÊ¼Ç°ºÍ½áÊøºóÉèÖÃÒ»¸ö¿ªÊ¼Ê±¼äºÍ½áÊøÊ±¼ä£¬ÓÃËûÃǵIJî×÷Ϊ³ÌÐòÖ´ÐеÄʱ¼ä¡£
ÎÒÃDz»·Á¶¨ÒåÒ»¸ö½Ó¿ÚÓÃjava»Øµ÷À´ÊµÏÖ¶¯Ì¬¼ÆËã¡£
½Ó¿Ú¶¨Ò壺
package com.hd123.h5.ejb.verctrl;
public interface CallBack {
public void callBack();
}
È»ºóÊÇʵÏÖÕâ¸ö½Ó¿Ú
package com.hd123.h5.ejb.verctrl;
public class Run {
//ÓÉÓÚ½Ó¿ÚÖÐµÄ callBack·½·¨ÊÇûÓж¨ÒåµÄ£¬ËùÒÔÓÃÒ»¸ö½Ó¿Ú¶ÔÏóÖ´ÐÐcallBack()·½·¨£¬ÆäʵÊÇδ֪µÄ£¬ÎÒÃǾßÌåÐèҪʵÏֵķ½·¨
//¿ÉÒÔͨ¹ýcallBack()£¬Õâ¸ö·½·¨µÄ²»Í¬ÊµÏÖÀ´ÊµÏÖ¶¯Ì¬¼ÆÊ±¡£
private void run(CallBack callBack, String event) {
long startTime = System.currentTimeMillis();
callBack.callBack();
long endTime = System.currentTimeMillis();
System.out.print("Ö´ÐÐ" + event + "¹²ÏûºÄ" + (endTime - startTime) + "ms");
}
public static void main(String[] args) {
Run r=new Run();
//ÕâÀﶯ̬µÄʵÏÖcallBack·½·¨¡£
r.run(new CallBack(){
public void callBack() {
for(int i=0;i<999;i++){
for(int j=i+1;j<99999;j++){
}
}
}
}, "Ñ»·");
}
}
Ïà¹ØÎĵµ£º
Javaѧϰ´ÓÈëÃŵ½¾«Í¨
Ò»¡¢ JDK (Java Development Kit)
JDKÊÇÕû¸öJavaµÄºËÐÄ£¬°üÀ¨ÁËJavaÔËÐл·¾³£¨Java Runtime Envirnment£©£¬Ò»¶ÑJava¹¤¾ßºÍJava»ù´¡µÄÀà¿â(rt.jar)¡£²»ÂÛʲôJavaÓ¦Ó÷þÎñÆ÷ʵÖʶ¼ÊÇÄÚÖÃÁËij¸ö°æ±¾µÄJDK¡£Òò´ËÕÆÎÕJDKÊÇѧºÃJavaµÄµÚÒ»²½¡£×îÖ÷Á÷µÄJ ......
ºÜ¶àÅóÓÑÔÚÉîÈëµÄ½Ó´¥ JAVA ÓïÑÔºó¾Í»á·¢ÏÖÕâÑùÁ½¸ö´Ê£º·´Éä (Reflection) ºÍÄÚÊ¡ (Introspector) £¬¾³£¸ã²»Çå³þÕâµ½µ×ÊÇÔõô»ØÊ£¬ÔÚʲô³¡ºÏÏÂÓ¦ÓÃÒÔ¼°ÈçºÎʹÓ㿽ñÌì°ÑÕâ¶þÕß·ÅÔÚÒ»Æð½éÉÜ£¬ÒòΪËüÃǶþÕßÊÇÏศÏà³ÉµÄ¡£
·´Éä
<o:p> </o:p>
Ïà¶Ô¶øÑÔ£¬·´Éä±ÈÄÚÊ¡¸üÈÝÒ×Àí½âÒ»µã¡£ÓÃÒ»¾ä±È½Ï°×µÄ»°À´¸ÅÀ ......
ÎÊ£º
²âÊÔÐÂÊÖ£¬¸ù¾Ý×Ô¼ºÀí½âдµÄµ¥Ôª²âÊÔÓÃÀýÄ£°å£¬µ«ÊÇ¿ª·¢ÈËÔ±(JAVAÓïÑÔ)·´Ó³ÄÑÒÔʵʩ£¬²»ÖªµÀµ½µ×Ó¦¸ÃÈçºÎ¸ÄÕý£¬ÎÒÔ±¾µÄÏë·¨ÊÇÒÔÀàΪµ¥Î»£¬ÎªÈ·±£²âÊÔ¸²¸ÇÂÊ£¬ÏÈ»¿ØÖÆÁ÷ͼ£¬ÒÀ¾Ý¶ÀÁ¢Â·¾¶È·¶¨ÊäÈëÊä³ö£¬ÓÐÁËÊäÈëÊä³ö¾ÍËãÒ»¸öÓÃÀýÁË£¬µ«´ó¼Ò·´Ó³£¬Ò»ÀàΪµ¥Î»»¿ØÖÆÁ÷ͼ²»ºÃ»£¬ÀàÖпÉÄÜÉæ¼°ºÜ¶àº¯Ê ......
Ò»¡¢Í¬²½ÎÊÌâÌá³ö
Ï̵߳Äͬ²½ÊÇΪÁË·ÀÖ¹¶à¸öÏ̷߳ÃÎÊÒ»¸öÊý¾Ý¶ÔÏóʱ£¬¶ÔÊý¾ÝÔì³ÉµÄÆÆ»µ¡£
ÀýÈ磺Á½¸öÏß³ÌThreadA¡¢ThreadB¶¼²Ù×÷ͬһ¸ö¶ÔÏóFoo¶ÔÏ󣬲¢ÐÞ¸ÄFoo¶ÔÏóÉϵÄÊý¾Ý¡£
public class Foo {
private int x = 100;
public int getX() {
&nbs ......
ÏÂÊöÊ®Ëĸö¼¼ÇÉ£¬ÊÇÐí¶àÈËÔÚ´óÁ¿µÄÊý¾Ý¿â·ÖÎöÓëÉè¼ÆÊµ¼ùÖУ¬Öð²½×ܽá³öÀ´µÄ¡£¶ÔÓÚÕâЩ¾ÑéµÄÔËÓ㬶ÁÕß²»ÄÜÉú°ïÓ²Ì×£¬ËÀ¼ÇÓ²±³£¬¶øÒªÏû»¯Àí½â£¬ÊµÊÂÇóÊÇ£¬Áé»îÕÆÎÕ¡£²¢Öð²½×öµ½£ºÔÚÓ¦ÓÃÖз¢Õ¹£¬ÔÚ·¢Õ¹ÖÐÓ¦Óá£
1. Ôʼµ¥¾ÝÓëʵÌåÖ®¼äµÄ¹ØÏµ
¡¡¡¡
¿ÉÒÔÊÇÒ»¶ÔÒ»¡¢Ò»¶Ô¶à¡¢¶à ......