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

JAVAÖеÄSingletonģʽ

µ¥Àýģʽ£¬¹ËÃû˼Ò壬ֻÄÜÓÐÒ»¸öʵÀý¡£
Ò».´Ó¶àḬ̈߳²È«ËµÆð£¬ÈçÏÂͼ´úÂ룬´ËÎÊÌâ¿ÉÒÔÓÃsynchronized¹Ø¼ü×ÖÀ´½â¾ö¡£¸Ã·½·¨È±µã£ºÃ¿Ò»¸öÏß³ÌÔÚ»ñȡʵÀý¶ÔÏó֮ǰ¶¼ÒªÔÚsynchronizedÉÏͬ²½µÄ¶ÔÏóÉϽøÐеȴý£¬Òò´ËЧÂʲ»¸ß¡£
¶þ.Double Check·½·¨£¬¼ûÏÂͼ´úÂë¡£Double CheckµÄ³õÖÔÊÇÖ»Óе±instanceΪNULLʱִÐеÄÏ̲߳ÅÐèÒªÔÚsynchronizedͬ²½µÄ¶ÔÏóÉϵȴý£¬Õâ±ÜÃâÁË“Ò»”·½·¨ÖеÄÿ¸öÏß³ÌÔÚ»ñµÃʵÀý¶ÔÏó֮ǰ¾ùÒªÔÚsynchronizedͬ²½µÄ¶ÔÏóÉϽøÐеȴýµÄ±×¶Ë¡£µ«ÊÇÕâÒ»ÉèÏëÔÚJAVAÖÐÈ´²»ÊÊÓ¦¡£Ô­Òò£ºJAVAÄÚ´æÄ£ÐͲ¢²»±£Ö¤Ò»¸ö¶ÔÏóµÄÒýÓÃÖ»ÓÐÔÚËü¹¹ÔìÍêÖ®ºó²Å±»¸³ÓèÒ»¸öʵÀý¡£ÀýÈ磺AÏß³ÌÖ´Ðе½ÁËinstance=new SingletonClass();"instance=new SingletonClass()"ÕâÒ»¹ý³ÌµÄÖ´Ðв½Öè¿ÉÄÜÊÇÏÂÊöÇéÐΣºµÚÒ»²½£¬JVM·ÖÅäÄڴ棻µÚ¶þ²¿£¬instanceÖ¸Ïò·ÖÅäµÄÄڴ棻µÚÈý²½£¬µ÷Óù¹Ôì·½·¨¡£¼ÙÉè´ËʱAÏß³ÌÖ´Ðе½Á˵ڶþ²½£¬¶øͬʱBÏ߳̿ªÊ¼Ö´ÐУ¬´ËʱBÏ̼߳ì²âµ½µÄinstance²»Îªnull£¬µ«ÒòΪAÏß³ÌÖл¹Î´Ö´ÐеÚÈý²½¼´»¹Ã»µ÷Óù¹Ô캯Êý£¬ËùÒÔBÏß³ÌÖзµ»ØµÄinstanceÊDz»ÕýÈ·µÄ¡£µ±È»£¬ÕâÖÖ´íÎóʱ¿ÉÄÜ·¢ÉúµÄ£¬¾¡¹ÜÏÂÃæ´úÂëÖеÄÖ´Ðеõ½µÄ½á¹ûÊÇÕýÈ·µÄ¡£
Èý.ʹÓþ²Ì¬ÄÚ²¿Àà¡£ºÃ´¦£º1.¿ÉÒÔʵÏÖÑÓʱʵÀý»¯¡£¼´Ö»Óе±Ààµ÷ÓÃgetInstance()·½·¨Ê±²Å»á¶Ôinstance½øÐÐʵÀý»¯£¬¶ø“Ò»”“¶þ”Á½ÖÖ·½·¨Öж¼ÊÇÔÚÀàµÚÒ»´Î¼ÓÔØʱ±ã¶Ôinstance½øÐÐÁËʵÀý»¯¡£2.½â¾öÁË“Ò»”·½·¨ÖУ¬Ã¿¸öÏß³ÌÔÚ»ñµÃʵÀý¶ÔÏó֮ǰ¶¼ÒªÔÚsynchronizedͬ²½µÄ¶ÔÏóÉϽøÐеȴýµÄȱÏÝ¡£
ÎÊÌ⣺ÕâÊÇÍøÂçÉÏ¿´µ½µÄ´ò¼ÜÆÕ±éÈÏͬµÄÒ»ÖÖ½â¾öjavaÖÐSingletonģʽµÄ·½·¨£¬µ«ÎªÊ²Ã´ÏÂÃæÕâÖÖ·½·¨²»´æÔÚDouble Check·½·¨Öеı׶ËÄØ£¿¼´ÏÂÃæ·½·¨ÖÐÊÇͨ¹ýʲô½â¾öÁËDouble CheckÖеÄÎÊÌâÄØ£¿
 


Ïà¹ØÎĵµ£º

FlexÖÐRemoteObjectÓëjavaµÄ½»»¥ÊµÀý½²½â

 Õ⼸ÌìÒ»Ö±ÔÚÑо¿FlexÖÐRemoteObjectÓëjavaµÄ½»»¥ÎÊÌ⣬¿ÉÒ»Ö±²»³É¹¦£¬½ñÌìÖÕÓڳɹ¦ÁË£¬µ«ÊÇ»¹ÓÐһЩÒÉ»ó£¬Ó¦¸Ã¼ÌÐøŬÁ¦¡£
ÏÂÃæÊÇÎҵľ­¹ýºÍÅöµ½µÄ´íÎó£º
£¨1£©ÏÂÔغͰ²×°lcds.
ÔÚ°²×°Ä¿Â¼Ï»áÓÐÈçÏÂÎļþ£¬ÆäÖÐlcds.war¿ÉÒÔ×÷ΪÎÒÃÇ¿ª·¢FlexÓëjava½»»¥µÄÄ£°æ£¬°ÑÕâ¸öÎļþ¿¼µ½ÄãtomcatµÄwebappsÏ£¨µ±È»ÕâÖÖÇé¿öÊÇÄ ......

һЩÄãÐèÒªÖªµÀµÄJava±à³Ì´úÂë¹æ·¶

Ê×ÏÈ£¬Ç¿ÁÒÍƼöÄãÏȲο¼Sun¹Ù·½µÄJava´úÂë/±à³Ì¹æ·¶£º
http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html

Äã¿ÉÒÔ´òÆÆÒÔÉϵÄÈÎÒ»¹æÔò£¬²»¹ýÒ»¶¨ÒªÓиöºÃÀíÓÉ£¬²¢ÇҼǼÏÂÀ´¡£
ÓÀÔ¶£¬ÓÀÔ¶£¬ÓÀÔ¶²»ÒªÔÚûÓмǼ¶ÑÕ»¸ú×ÙÐÅÏ¢£¨stack trace£©»òÊÇÖØÐÂÅ׳öÒì³£µÄÇé¿öϲ¶»ñÒì³££¬Ë׳Ɠ³ÔµôÒì³£&rd ......

JavaÐÂÊÖÈëÃźÜÖØÒªµÄ¼¸¸ö»ù±¾¸ÅÄî

 finalÀࣺΪ·ÀÖ¹ËûÈË´ÓÄãµÄÀàÉÏÅÉÉúÐÂÀ࣬´ËÀàÊDz»¿ÉÀ©Õ¹µÄ¡£
¡¡¡¡¶¯Ì¬µ÷ÓñȾ²Ì¬µ÷Óû¨·ÑµÄʱ¼äÒª³¤¡£
¡¡¡¡³éÏóÀࣺ¹æ¶¨Ò»¸ö»ò¶à¸ö³éÏó·½·¨µÄÀà±¾Éí±ØÐ붨ÒåΪabstract¡£
¡¡¡¡Àý£º public abstract string getDescripition
¡¡¡¡JavaÖеÄÿһ¸öÀ඼ÊÇ´ÓObjectÀàÀ©Õ¹¶øÀ´µÄ¡£
¡¡¡¡objectÀàÖеÄequalºÍtoString·½· ......

JAVA Ìåϵ¼°Æä±à³ÌµÄ¹ý³Ì

 JAVA Ìåϵ¼°Æä±à³ÌµÄ¹ý³Ì
  °¥£¬±ÏÒµÁËÒ²Ò»¶Îʱ¼äÁË£¬Ö»ÖªµÀÌìÌì³­´úÂ룬 JAVA µÄ»ù´¡ÖªÊ¶»ù±¾ÊÇÍüµôÁË£¬¼ÓÉÏÒÔǰһֱûÓÐϵͳµØѧϰ¹ý£¬¸Ð¾õ¿ìÒª·ÏÁË¡£»¹ÊǺúþ²ÏÂÐÄÀ´Ñ§Ñ§»ù´¡°É¡£²»ÄÜÌìÌ쿼³­´úÂë¹ýÈÕ×Ó°¡¡£¡£¡£¡££¨ÏÂÎÄ´ó¶àÀ´×Կα¾ÒÔ¼°Ò»Ð©¼¼ÊõÊÓƵÉϵÄÄÚÈÝ£¬»ù±¾Àí½âÁËһЩÁË£¬Ê£ÏµÄÓÉÒÔºóµÄѧϰÂýÂýÔ ......

Java ÄÚ²¿Àà

¶¨ÒåÔÚÒ»¸öÀàÄÚ²¿µÄÀà½ÐÄÚ²¿À࣬°üº¬ÄÚ²¿ÀàµÄÀà³ÆΪÍⲿÀà¡£
ÄÚ²¿Àà¿ÉÒÔÉùÃ÷public¡¢protected¡¢privateµÈ·ÃÎÊÏÞÖÆ£¬
¿ÉÒÔÉùÃ÷ΪabstractµÄ¹©ÆäËûÄÚ²¿Àà»òÍⲿÀà¼Ì³ÐÓëÀ©Õ¹£¬
»òÕßÉùÃ÷Ϊstatic¡¢finalµÄ£¬Ò²¿ÉÒÔʵÏÖÌض¨µÄ½Ó¿Ú¡£
staticµÄÄÚ²¿ÀàÐÐΪÉÏÏóÒ»¸ö¶ÀÁ¢µÄÀ࣬
·ÇstaticÔÚÐÐΪÉÏÀàËÆÀàµÄÊôÐÔ»ò·½·¨ÇÒ½ûÖ¹ÉùÃ÷s ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ