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

javaµ¥Ì¬Ä£Ê½½²½â


µ¥Ì¬¶¨Òå:
        SingletonģʽÖ÷Òª×÷ÓÃÊDZ£Ö¤ÔÚJavaÓ¦ÓóÌÐòÖУ¬Ò»¸öÀàClassÖ»ÓÐÒ»¸öʵÀý´æÔÚ¡£
        Singletonģʽ¾ÍΪÎÒÃÇÌṩÁËÕâÑùʵÏֵĿÉÄÜ¡£Ê¹ÓÃSingletonµÄºÃ´¦»¹ÔÚÓÚ¿ÉÒÔ½ÚÊ¡Äڴ棬ÒòΪËüÏÞÖÆÁËʵÀýµÄ¸öÊý£¬ÓÐÀûÓÚJavaÀ¬»ø»ØÊÕ£¨garbage collection£©¡£
ʹÓÃSingleton×¢ÒâÊÂÏ
        ÓÐʱÔÚijЩÇé¿öÏ£¬Ê¹ÓÃSingleton²¢²»ÄÜ´ïµ½SingletonµÄÄ¿µÄ£¬ÈçÓжà¸öSingleton¶ÔÏóͬʱ±»²»Í¬µÄÀà×°ÈëÆ÷×°ÔØ£»ÔÚEJBÕâÑùµÄ·Ö²¼Ê½ÏµÍ³ÖÐʹÓÃҲҪעÒâÕâÖÖÇé¿ö£¬ÒòΪEJBÊÇ¿ç·þÎñÆ÷£¬¿çJVMµÄ
µ¥Ì¬Ä£Ê½µÄÑÝ»¯£º
        µ¥Ì¬Ä£Ê½ÊǸö¼òµ¥µÄģʽ£¬µ«ÊÇÕâ¸ö¼òµ¥µÄģʽҲÓкܶิÔӵĶ«Î÷¡£
µ¥Ì¬Ä£Ê½Ò»:
i)
public class Singleton {
¡¡¡¡private Singleton(){}
¡¡¡¡//ÔÚ×Ô¼ºÄÚ²¿¶¨Òå×Ô¼ºÒ»¸öʵÀý£¬ÊDz»ÊǺÜÆæ¹Ö£¿
¡¡¡¡//×¢ÒâÕâÊÇprivate Ö»¹©ÄÚ²¿µ÷ÓÃ
¡¡¡¡private static Singleton instance = new Singleton();
¡¡¡¡//ÕâÀïÌṩÁËÒ»¸ö¹©Íⲿ·ÃÎʱ¾classµÄ¾²Ì¬·½·¨£¬¿ÉÒÔÖ±½Ó·ÃÎÊ¡¡
¡¡    public static Singleton getInstance() {
¡¡¡¡return instance;
¡¡}
¡¡}
ii)µÈͬÓÚÉÏÒ»ÖÖ
public class Singleton {
¡¡¡¡//×¢ÒâÕâÊÇprivate Ö»¹©ÄÚ²¿µ÷ÓÃ
       private Singleton(){}
¡¡¡¡private static Singleton instance;
¡¡¡¡//ÕâÀïÌṩÁËÒ»¸ö¹©Íⲿ·ÃÎʱ¾classµÄ¾²Ì¬·½·¨£¬¿ÉÒÔÖ±½Ó·ÃÎÊ¡¡
¡¡    public static Singleton getInstance() {
¡¡¡¡   if (instance == null)     
              instance = new Singleton();  
          return instance;      
¡¡}
¡¡}
×¢Ò⣺Õâ¸öµ¥Ì¬Ä£Ê½ÊDz»°²È«µÄ£¬ÎªÊ²Ã´ËµÄØ £¿ÒòΪû¿¼ÂǶàỊ̈߳¬ÈçÏÂÇé¿ö
        Thread 1 µ÷ÓÃgetInstance() ·½·¨£¬²¢ÇÒÅжÏinstanceÊÇnull£¬È»áá½øÈëifÄ£¿é£¬ÔÚʵÀý»¯instance֮ǰ£¬Thread 2ÇÀÕ¼ÁËThread 1µÄcpu¡£Thread 2 µ÷ÓÃgetInstance() ·½·¨£¬²¢ÇÒÅжÏinstanceÊÇnull£¬È»áá½øÈëifÄ£¿é£¬Thread 2 ʵÀý»¯instance Íê³É£¬


Ïà¹ØÎĵµ£º

javaÐÔÄܼà¿Ø¹¤¾ß btrace

btraceÊÇsunÍƳöµÄÒ»¿îjavaÐÔÄܼà¿Ø¹¤¾ß£¬ÀûÓÃjava agent ºÍ jvm attach¼¼Êõ£¬¿ÉÒÔ²»Í£»úµÄÇé¿öϼà¿ØÏßÉÏÇé¿ö£¬²¢ÇÒ×öµ½×îÉÙµÄÇÖÈ룬ռÓÃ×îÉÙµÄϵͳ×ÊÔ´¡£
Ïêϸ¼û¹Ù·½Îĵµ
ÁíÍâbtraceÓкÜÑϸñµÄÏÞÖÆ£¬±ÈÈçÆ´½Ó×Ö·û´®¡¢Ñ­»·¡¢µÝ¹é¡¢ÒÔ¼°ÎÒÃÇƽʱ¾­³£ÓõÄһЩ·½·¨¶¼²»¿ÉÒÔÓã¬ËûÓÐËû×Ô¼º×¨ÃŵÄÀà¿â¡£
btrace»¹ÌṩÁËVi ......

JAVA GC

Êܵ½“15ÄêÄã»ýÀÛÁËʲô”Ò»ÎĵÄÕ𶯣¬ÌرðÊÕ¼¯¸ÃÎÄѧϰ
Java gc
¹Ø¼ü×Ö: java gc, À¬»ø»ØÊÕ»úÖÆ
1.JVMµÄgc¸ÅÊö
¡¡¡¡gc¼´À¬»øÊÕ¼¯»úÖÆÊÇÖ¸jvmÓÃÓÚÊÍ·ÅÄÇЩ²»ÔÙʹÓõĶÔÏóËùÕ¼ÓõÄÄÚ´æ¡£javaÓïÑÔ²¢²»ÒªÇójvmÓÐgc£¬Ò²Ã»Óй涨gcÈçºÎ¹¤×÷¡£²»¹ý³£ÓõÄjvm¶¼ÓÐgc£¬¶øÇÒ´ó¶àÊýgc¶¼Ê¹ÓÃÀàËƵÄËã·¨¹ÜÀíÄÚ´æºÍÖ´ÐÐÊÕ ......

JAVAºÍPHPÎļþ²Ù×÷×ܽá

JAVAÎļþ²Ù×÷×ܽá
FileÀà
File f = new File(path);
pathΪʵ¼Ê·¾¶£¬¸Ã·¾¶¿ÉÒÔÊÇÎļþ£¬»òÎļþ¼Ð£¬Ò²¿ÉÒÔÊDz»´æÔڵġ£
f.exists() ¿ÉÒÔÅжϸ÷ÊÇ·ñ´æÔÚ¡£
f.isDirectory() ¿ÉÒÔÅжÏÊÇ·ñÊÇÎļþ¼Ð¡£
f.mkdirs(); µÝ¹é´´½¨Îļþ¼Ð
FileºÍÊäÈëÊä³öÁ÷Ö®¼äŦ´øFileInutStream£¬FileOutputStream
URL url = new URL(strUr ......

JavaÖÐÆæ¹Ö¶øÓÖÎ޿ɺñ·ÇµÄÀà¼ÓÔØ˳Ðò

×òÌì¿´µ½ÕâÑùһƪÌû×Ó£¬ÌÖÂÛÀà¼ÓÔØ˳ÐòµÄ£¬Ò²¿ÉÒÔ˵Êdzõʼ»¯Ë³ÐòµÄ£¬½ñÌìÔçÉÏÕÒ²»µ½ÁË£¬±¾À´Ïë»Ø¸´µÄ£¬ÏÖÔÚ×Ô¼ºÐ´²©¿Í»Ø¸´ÁË£¬ºÇºÇ
public class Singleton {   
private static Singleton obj = new Singleton();   
public static int counter1 ;   
public static int counter2 = 0;& ......

JavaʵÏÖCSVÎļþ²îÒì¶Ô±È

ÔÚÏîÄ¿Öо­³£»áÓöµ½Ê¹ÓÃCSVÎļþ£¬±ÈÈç´ÓHRÖеõ½µÄÎļþÄõ½ÆäËüµØ·½È¥´¦Àí£¬Êµ¼Ê»áÐèÒªµÃµ½µ±Ç°ºÍÉÏ´ÎÎļþÖеIJîÒ죬±ÈÈ磺Ìí¼Ó£¬É¾³ý£¬Ð޸ģ¬ ÄÇôÈçºÎÀ´ÊµÏÖÄØ£¬¿ÉÄÜÓкܵķ½·¨£¬ÔÚÕâÀïÎÒ˵һÏÂÎÒµÄʵÏÖ·½·¨¶øÇÒÒÑͶÈëʵ¼ÊʹÓá£
Ê×ÏÈ£¬ CSVÎļþµäÐÍÒÔ,·Ö¸ô£¬µ±È»»¹ÓÐÆäËüµÄ×Ö·û£¬ÓɺܶàÁеÄÊôÐÔºÍÊôÐÔÖµ×é³É£¬ÄÇôÁ½¸öÎ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ