Java ÀíÂÛÓëʵ¼ù: ÓÃÈõÒýÓöÂסÄÚ´æй© 1
ËäÈ»Óà Java™ ÓïÑÔ±àдµÄ³ÌÐòÔÚÀíÂÛÉÏÊDz»»á³öÏÖ“ÄÚ´æй©”µÄ£¬µ«ÊÇÓÐʱ¶ÔÏóÔÚ²»ÔÙ×÷Ϊ³ÌÐòµÄÂ߼״̬µÄÒ»²¿·ÖÖ®ºóÈÔÈ»²»±»À¬»øÊÕ¼¯¡£±¾Ô£¬¸ºÔð±£ÕÏÓ¦ÓóÌÐò½¡¿µµÄ¹¤³Ìʦ Brian Goetz ̽ÌÖÁËÎÞÒâʶµÄ¶ÔÏó±£ÁôµÄ³£¼ûÔÒò£¬²¢Õ¹Ê¾ÁËÈçºÎÓÃÈõÒýÓöÂסй©¡£
ÒªÈÃÀ¬»øÊÕ¼¯£¨GC£©»ØÊÕ³ÌÐò²»ÔÙʹÓõĶÔÏ󣬶ÔÏóµÄÂß¼ ÉúÃüÖÜÆÚ£¨Ó¦ÓóÌÐòʹÓÃËüµÄʱ¼ä£©ºÍ¶Ô¸Ã¶ÔÏóÓµÓеÄÒýÓõÄʵ¼Ê ÉúÃüÖÜÆÚ±ØÐëÊÇÏàͬµÄ¡£ÔÚ´ó¶àÊýʱºò£¬ºÃµÄÈí¼þ¹¤³Ì¼¼Êõ±£Ö¤ÕâÊÇ×Ô¶¯ÊµÏֵģ¬²»ÓÃÎÒÃǶԶÔÏóÉúÃüÖÜÆÚÎÊÌ⻨·Ñ¹ý¶àÐÄ˼¡£µ«ÊÇż¶ûÎÒÃǻᴴ½¨Ò»¸öÒýÓã¬ËüÔÚÄÚ´æÖаüº¬¶ÔÏóµÄʱ¼ä±ÈÎÒÃÇÔ¤ÆÚµÄÒª³¤µÃ¶à£¬ÕâÖÖÇé¿ö³ÆΪÎÞÒâʶµÄ¶ÔÏó±£Áô£¨unintentional object retention£©¡£
È«¾Ö Map Ôì³ÉµÄÄÚ´æй©
ÎÞÒâʶ¶ÔÏó±£Áô×î³£¼ûµÄÔÒòÊÇʹÓà Map ½«ÔªÊý¾ÝÓëÁÙʱ¶ÔÏó£¨transient object£©Ïà¹ØÁª¡£¼Ù¶¨Ò»¸ö¶ÔÏó¾ßÓÐÖеÈÉúÃüÖÜÆÚ£¬±È·ÖÅäËüµÄÄǸö·½·¨µ÷ÓõÄÉúÃüÖÜÆÚ³¤£¬µ«ÊDZÈÓ¦ÓóÌÐòµÄÉúÃüÖÜÆڶ̣¬Èç¿Í»§»úµÄÌ×½Ó×ÖÁ¬½Ó¡£ÐèÒª½«Ò»Ð©ÔªÊý¾ÝÓëÕâ¸öÌ×½Ó×Ö¹ØÁª£¬ÈçÉú³ÉÁ¬½ÓµÄÓû§µÄ±êʶ¡£ÔÚ´´½¨ Socket ʱÊDz»ÖªµÀÕâЩÐÅÏ¢µÄ£¬²¢ÇÒ²»Äܽ«Êý¾ÝÌí¼Óµ½ Socket ¶ÔÏóÉÏ£¬ÒòΪ²»ÄÜ¿ØÖÆ Socket Àà»òÕßËüµÄ×ÓÀà¡£Õâʱ£¬µäÐ͵ķ½·¨¾ÍÊÇÔÚÒ»¸öÈ«¾Ö Map Öд洢ÕâЩÐÅÏ¢£¬ÈçÇåµ¥ 1 ÖÐµÄ SocketManager ÀàËùʾ£º
Çåµ¥ 1. ʹÓÃÒ»¸öÈ«¾Ö Map ½«ÔªÊý¾Ý¹ØÁªµ½Ò»¸ö¶ÔÏó
public class SocketManager {
private Map<Socket,User> m = new HashMap<Socket,User>();
public void setUser(Socket s, User u) {
m.put(s, u);
}
public User getUser(Socket s) {
return m.get(s);
}
public void removeUser(Socket s) {
m.remove(s);
}
}
SocketManager socketManager;
...
socketManager.setUser(socket, user);
ÕâÖÖ·½·¨µÄÎÊÌâÊÇÔªÊý¾ÝµÄÉúÃüÖÜÆÚÐèÒªÓëÌ×½Ó×ÖµÄÉúÃüÖÜÆÚ¹Ò¹³£¬µ«Êdzý·Ç׼ȷµØÖªµÀʲôʱºò³ÌÐò²»ÔÙÐèÒªÕâ¸öÌ×½Ó×Ö£¬²¢¼Çס´Ó Map ÖÐɾ³ýÏàÓ¦µÄÓ³É䣬·ñÔò£¬Socket ºÍ User ¶ÔÏ󽫻áÓÀÔ¶ÁôÔÚ Map ÖУ¬Ô¶Ô¶³¬¹ýÏìÓ¦ÁËÇëÇóºÍ¹Ø±ÕÌ×½Ó×ÖµÄʱ¼ä¡£Õâ»á×èÖ¹ Socket ºÍ User ¶ÔÏó±»À¬»øÊÕ¼¯£¬¼´Ê¹Ó¦ÓóÌÐò²»»áÔÙʹÓÃËüÃÇ¡£ÕâЩ¶ÔÏóÁôÏÂÀ´²»ÊÜ¿ØÖÆ£¬ºÜÈÝÒ×Ôì³É³ÌÐòÔÚ³¤Ê±¼äÔËÐкóÄڴ汬Âú¡£³ýÁË×î¼òµ¥µÄÇé¿ö£¬ÔÚ¼¸ºõËùÓÐÇé¿öÏÂÕÒ³öʲôʱºò Socket ²»ÔÙ±»³ÌÐòʹÓÃÊÇÒ»¼þºÜ·³È˺ÍÈÝÒ׳ö´íµÄÈÎÎ
Ïà¹ØÎĵµ£º
1.
Ôö¼ÓJavaÓ¦ÓÃ
ÔÚandroid_2.1/packages/appsÔö¼Ó¸ÃÏîÄ¿£»
ÔÚbuild/target/product/generic.mkµÄPRODUCT_PACKAGESºóÃæÔö¼Ó¶ÔÓ¦°üµÄÃû×Ö¡£
1.1
´ÓÃüÁîÐ ......
ѧjavaÒ²½«½ü¿ìÁ½ÄêµÄʱ¼äÁË£¬Ö®Ç°Ñ§¹ýµÄ¶«Î÷×Ô¼º¸Ð¾õÓеãÄ£ºý£¬ÀíÂÛÕÆÎյIJ»ÊǺÜ͸³¹£¬ÓÐЩÎÊÌâ½â¾öµÄÒ²²»ÊǺÜÈ«Ã棬Ϊ´ËÔÚ´óѧ±ÏҵǰϦ£¬Ïë°Ñ֪ʶºÃºÃµÄÊáÀíһϣ¬°Ñ×Ô¼º¶Ô¼¼ÊõµÄÒɵãºÍһЩÑо¿ÐĵÃдµ½csdn²©¿ÍÉÏ¡£ ......
1. ÈçºÎµÃµ½JavaÓ¦ÓóÌÐòµÄ¿ÉÓÃÄڴ棿
´ð£ºÈçÏ´úÂëʵÏÖÈ¡µÃ×ܵÄÄÚ´æ´óСºÍ¿ÉÓÃÄÚ´æ´óС£¬²¢´òÓ¡µ½¿ØÖÆ̨ÉÏ
public class MemoryExp {
public static void main(String[] args) {
System.out.println("Total Memory"+Runtime.getRuntime().totalMemory());
System.out.println("Free Memory ......
ÔÎÄÀ´×ÔÓÚ¡¶Developing Games in Java¡·£¬×÷ÕߣºDavid Brackeen, Bret Barker, Laurence Vanhelsuwé
JavaÔÚÉè¼Æʱ³ä·Ö¿¼ÂÇÁËÏß³Ì,Òò´ËÔÚJavaÖÐÏ̵߳IJÙ×÷±ÈÆäËûÓïÑÔÒª¼òµ¥¡£Ö»ÐèÉú³ÉÒ»¸öThreadÀàµÄʵÀý±ã¿É´´½¨Ò»¸öỊ̈߳¬È»ºóµ÷ÓÃstart()·½·¨Ï߳̾ÍÆô¶¯ÁË¡£
&nbs ......
ÀàÃû£º
java.util.Date
¹¹Ôì·½·¨£º
¹¹Ôì·½·¨ ½â˵
Date()
ÎÞ²ÎÊýµÄ¹¹Ôì·½·¨£¬½«¹¹½¨Ò»¸ö±£³Öµ±Ç°ÈÕÆÚ.ʱ¼äµÄDate¶ÔÏó¡£
Date(long time)
²ÎÊýΪ1970Äê1ÔÂ1ÈÕ00ʱ00·Ö00ÃëÆðËù¾¹ýµÄºÁÃëÊý£¬½«¹¹½¨Ò»¸ö±£³Ö¸ÃÈÕÆÚ.ʱ¼äµÄ¾«È·µ½ºÁÃëµÄDate¶ÔÏó¡£
ÆäËûÓÐЩ¹¹Ôì·½·¨ÒѾ²»ÍƼöʹÓã¬ÕâÀï² ......