jsonÊý¾ÝÖÐÎijöÏÖu0000Õâ¸öÎÊÌâ±ÈÔÚphpÖгöÀ´¿Õ°×ÒªºÃµãÁË£¬ÄÇôÕâÖÖÒªÈçºÎÀ´½â¾ö£¬ÏÂÃæÎÒÃÇÒ»ÆðÀ´¿´spring-webmvc-4.1.6 ½Ó¿Ú·µ»ØjsonÊý¾ÝÖÐÎijöÏÖu0000ÎÊÌâ°É£¬¾ßÌåÈçÏ¡£
֮ǰ´î½¨¿ª·¢»·¾³µÄʱºòÓöµ½ÁËÒ»¸öÆæ¹ÖµÄÏÖÏó£¬Ê¹ÓÃspring4.1.6µÄ¿ò¼Ü£¬ÒòΪspringµÄÉý¼¶´¦ÀíjsonµÄjarÒ²¸ú×ÅÉý¼¶µ½ÁËJackson2.6µÄrc1°æ¡£¾ßÌåÒýÈëµÄjarÈçÏÂͼËùʾ£º
»·¾³´î½¨ºÃºóд½Ó¿Ú²ÉÓÃjsonÊý¾Ý´«µÝ£¬¸Õ¿ªÊ¼Ã»Ê²Ã´ÎÊÌ⣬µ«ÊÇÓÐÒ»Ìì±£´æÁË´óÁ¿µÄÎÄ×ÖÐÅÏ¢£¬ÔÚ²éѯ·µ»ØµÄʱºò³öÏÖÁ˱àÂëÎÊÌ⣬ÈçͼËùʾ£º
ÕâÊÇʲô¹í£¬µ÷ÊÔÁ˺ó¤Ê±¼äÒ²ÕÒ³öÎÊÌâÀ´£¬ÖÐÎÄÊäÈëÒ»°ãÇé¿öÏÂûÓÐÎÊÌ⣬ֻÓм¸ÆªÎĵµ»á³öÏÖÕâÖÖÇé¿ö£¬ÒÔΪÊÇÎĵµÀïʲôÒþº¬µÄÌØÊâ×Ö·ûµ¼Öµģ¬¸÷ÖÖ³¢ÊÔ£¬Ò»¸ö¸ö×Ö¸´ÖƵij¢ÊÔ£¬¶¼²»ºÃʹ£¬Ê±ºÃʱ»µ£¬ÕæÊǼ±ÈËѽ¡£
ËùÓеÄÎÊÌâ×ÜÓÐËü³öÏÖµÄÔÒò£¬Ò²ÓжÔÓ¦µÄ½â¾ö°ì·¨¡£×îºó»¹ÊDZ»·¢ÏÖÁ˹æÂÉ£¬¾ÍÊÇ¿ò¼ÜÀïÒýÈëµÄjson½âÎöjarÔÚÖÐÎĺº×ÖÔÚ³¬¹ýÒ»¶¨³¤¶ÈµÄʱºò¾Í»á³öÏÖÕâÖÖÇé¿ö¡£¹û¶Ï¸ü»»ÁËjarºóÎÊÌâÒ²¾Í²»´æÔÚÁË¡£¸ü»»µÄjarÈçÏÂͼËùʾ£º
¸ü»»jarºó£¬ÊäÈëÔÙ¶àµÄÖÐÎÄҲûÓÐÂÒÂëÁË£¬ÐÄÇéͻȻ¾ÍºÃÁË£¬ÏÂͼËùʾ£º
×ܽ᣺¿ò¼Ü´î½¨ÓÈÆäÊÇÉý¼¶Ê¹Óÿò¼Ü°æ±¾µÄʱºò£¬ÎÒÃÇÓ¦¸Ã¶à×öһЩ¼¼Êõµ÷ÑУ¬Á˽âÉý¼¶°æ±¾µÄÓÅȱµã£¬¾¡Á¿Ñ¡ÔñÎȶ¨°æ×÷ΪÕýʽʹÓõİ汾£¬ÕâÑù±£Ö¤ÎÒÃÇ¿ª·¢Äܹ»Õý³£½øÐУ¬ÏîÄ¿Äܹ»Ë³ÀûÉÏÏß¡£ÔÚÓöµ½ÎÊÌâʱҲӦ¸ÃÀä¾²·ÖÎö£¬ÕÒ¹æÂÉ£¬ÕÒ±¾Ô´£¬´Ó¸ù±¾ÉϽâ¾öÎÊÌâ¡£
¶ÑÒç³öÊÇÒòΪ²Ù×÷²»µ±»ò³ÌÐòûÓп¼Âǵ½ÄÚ´æµÄÒ»¸öÎÊÌ⣬½ñÌìÎÒÃÇÀ´¿´Java¶ÑÒç³öÖ®OutOfMemoryErrorÒì³£ÎÊÌâ¼°ËüµÄ½â¾ö°ì·¨£¬¾ßÌåµÄÈçÏ¡£
ÔÚJavaÐéÄâ»ú¹æ·¶µÄÃèÊöÖУ¬³ýÁ˳ÌÐò¼ÆÊýÆ÷Í⣬ÐéÄâ»úÄÚ´æµÄÆäËû¼¸¸öÔËÐÐʱÇøÓò¶¼Óз¢ÉúOutOfMemoryError£¨ÏÂÃ涼½ÐOOM£©Òì³£µÄ¿ÏÄÜ£¬ÏÂÃæ¾Íͨ¹ýһЩʵÀýÀ´ÑéÖ¤Òì³£·¢ÉúµÄ³¡¾°¡£ ÔÚÏÂÃæ¾ÙµÄÀý×ÓÖУ¬ÔÚ×¢ÊÍÖлáÉ趨һЩÐéÄâ»úµÄ²ÎÊý£¬ÔÚ”VM Args”ºó±ß£¬Èç¹ûÄãÊÇÓÿØÖÆ̨ÃüÁîÀ´Ö´ÐеijÌÐò£¬Ö±½Ó°ÑÕâЩ²ÎÊý·Åµ½JavaÃüÁîÖ®ºó¾ÍÐУ¬Èç¹ûÓõĿª·¢¹¤¾ß£¬Eclipse IDE£¬²ÅDebug/RunҳǩÖÐÉèÖá£
Java¶ÑÒç³ö
¶ÑÊÇÓÃÀ´´æ´¢¶ÔÏóʵÀýµÄ£¬µ±ÎÒÃDz»¶ÏµÄ´´½¨¶ÔÏ󣬲¢ÇÒ±£Ö¤GC RootsºÍ¶ÔÏóÖ®¼äÓÐÏ໥µÄÒýÓùØϵ£¨GC RootsÖ¸À¬»ø»ØÊÕÆ÷µÄ¶ÔÏó£¬GC»áÊÖ»úÄÇЩ²»ÊÇGC RootsÇÒûÓб»GC RootsÒýÓõĶÔÏ󣩣¬µ±¶ÔÏóÊýÁ¿´ïµ½×î´ó¶ÑµÄÈÝÁ¿µÄʱºò£¬¾Í»á²úÉúÄÚ´æÒç³öÒì³£¡£
/**
* VM Args:-Xms20m -Xmx20m -XX:+HeapDumpOnOutOfMemoryError
* @author Administrator
*
*/
public class HeapOOM
{
static class OOMObject{
}
public static void main(String[] args){
List<OOMObject> list=new ArrayList<OOMObject>();
while(true){
list.add(new OOMObject());
}
}
}
ÉÏÊö´úÂëÖÐÏÞÖÆJava¶ÑµÄ´óСΪ20MB£¬²»¿ÉÀ©Õ¹£¨½«¶ÑµÄ×îСֵ-Xms ²ÎÊýÓë×î´óÖµ-Xmx²ÎÊýÉèÖÃΪһÑù¾Í¿ÉÒÔ±ÜÃâ¶Ñ×Ô¶¯À©Õ¹£©£¬Í¨¹ý -XX:+HeapDumpOnOutOfMemoryError µ±ÐéÄâ»ú³öÏÖÄÚ´æÒç³öµÄʱºòDump³öµ±Ç°µÄÄÚ´æ¶Ñת´¢¿ìÕÕÒÔ±ãºó±ß½øÐзÖÎö¡£ÔËÐнá¹ûÈçÏ£º
java.lang.OutOfMemoryError: Java heap space
Dumping heap to java_pid5504.hprof ...
Heap dump file created [27872304 bytes in 0.150 secs]
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2245)
at java.util.Arrays.copyOf(Arrays.java:2219)
at java.util.ArrayList.grow(ArrayList.java:242)
at java.util.ArrayList.ensureExplicitCapacity(ArrayList.java:216)
at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:208)
at java.util.ArrayList.add(ArrayList.java:440)
at test.HeapOOM.main(HeapOOM.java:20)
Ë¢ÐÂÏîÄ¿Äã¾Í¿ÉÒÔ¿´µ½¿ìÕÕÎļþ£¬¿ÉÒÔÓÃEclipse Memory AnalyzerÀ´´ò¿ª²¢½øÐзÖÎö¡£È·¶¨ÊÇMemory Leak£¬»¹ÊÇMemory Overflow¡£ ´¦Àí˼·£ºÈç¹ûÊÇÄÚ´æй©£¬Í¨¹ý¹¤¾ß½øÒ»²½²é¿´Ð¹Â©¶ÔÏóµ½GC RootsµÄÒýÓÃÁ´£¬ÕÒµ½Ð¹Â©¶ÔÏóÊÇÈçºÎºÍGC RootsÏà¹ØÁª²¢µ¼ÖÂÀ¬»ø»ØÊÕÆ÷ÎÞ·¨×Ô¶¯»ØÊÕÕâЩ¶ÔÏóµÄ¡£ºó±ß¾Í¿ÉÒÔÅжϲúÉúÄÚ´æÒç³öµÄ´úÂëµÄλÖᣠÈç¹û²»´æÔÚÄÚ´æй©ÎÊÌ⣬¼ì²éÐéÄâ»úµÄ¶Ñ²ÎÊý£¨-Xms -Xmx£©¸úÎïÀí»úÆ÷¶Ô±ÈÊÇ·ñ»¹¿ÉÒÔµ÷´ó£¬ÔÚ´úÂë²ãÃæÉÏ¿´¿´ÊÇ·ñ´æÔÚijЩ¶ÔÏóÉúÃüÖÜÆÚ¹ý³¤¡¢³ÖÓÐ״̬ʱ¼ä¹ý³¤µÄÇé¿ö¡£¼õÉÙ³ÌÐòÔËÐÐÆÚ¼äµÄÄÚ´æÏûºÄ¡£
×¢Èë¶ÔÓÚ·þÎñÆ÷°²È«À´½²ÊǷdz£µÄÖØÒªÁËÎÒÃǽñÌìÀ´¿´Ò»Æª¹ØÓÚjavaÖÐÒÀÀµ×¢ÈëºÍ·þÎñ¶¨Î»Æ÷µÄÒ»¸ö½éÉÜÁË£¬Ï£ÍûÏÂÃæÕâƪÎÄÕ¶Ը÷λÓаïÖú¡£
ÔÚJavaÉçÇøÓÐÒ»¹ÉʹÓÃÇáÁ¿¼¶ÈÝÆ÷À´°ïÖú×é×°²»Í¬ÏîÄ¿µÄ×é¼þ¡¢¼¯³Éµ½Ò»¸öÓÐÄý¾ÛÁ¦µÄÓ¦ÓóÌÐòµÄÈȳ±¡£
ÕâЩµ×²ãÈÝÆ÷ÓÐÒ»ÖÖÆÕ±éµÄģʽȥչʾËûÃÇÈçºÎ×°Åä×é¼þ£¬ËûÃÇÌá³öÒ»¸ö¸ÅÄÃûΪ“¿ØÖÆ·´×ª”£¨Inversion of Control£©¡£
½ÓÏÂÀ´ÎÒÃÇÉîÈëÍÚ¾òÏÂÕâ¸öģʽÔÚ“ÒÀÀµ×¢È딣¨Dependency Injection£©ÔõôÔË×÷µÄ£¬²¢ÇÒ¸ú·þÎñ¶¨Î»Æ÷½øÐжԱȡ£
×é¼þºÍ·þÎñ
ÎÒ˵µÄʹÓÃ×é¼þÒâζ×Å£¬ºÜ¶àÈí¼þÄÜ×ÔÓɵÄʹÓÃËü£¬²»Ðè¸Ä±ä£¬ÒòΪÕâ¸ö×é¼þÒѾ²»ÊÜ×÷ÕߵĿØÖÆ¡£
µ±ÎÒÃÇÔÚÍⲿϵͳÖÐʹÓõÄʱºò£¬·þÎñÀàËÆ×é¼þ¡£
ΨһµÄ²»Í¬µãÊÇÎÒÆÚÍûÔÚ±¾µØʹÓÃ×é¼þ£¨eg jar file£¬assembly£¬dll£¬or source inport£©¡£
·þÎñͨ¹ýÔ¶³Ì½Ó¿ÚÀ´Ô¶³Ìµ÷Ó㬿ÉÒÔͬ²½»òÕßÒì²½²Ù×÷¡£(eg web service, messaging system, RPC, or socket.)
ÒÀÀµ×¢Èë
injector
·ÖΪÈýÖÖÀàÐÍ£º¹¹ÔìÆ÷×¢Èë¡¢setter×¢Èë¡¢½Ó¿Ú×¢Èë¡£
1 ¹¹ÔìÆ÷£º
class MovieLister...
public MovieLister(MovieFinder finder) {
this.finder = finder;
}
2 setter£º
class MovieLister...
private MovieFinder finder;
public void setFinder(MovieFinder finder) {
this.finder = finder;
}
setterµÄxmlÅäÖÃ
¡¡