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

javaÏß³Ìͬ²½ÎÊÌâ

Ò»°ã£¬ÓÐ3ÖÖʹÓÃËø½øÐÐͬ²½µÄ·½·¨
    a.·½·¨Í¬²½£¬ÀýÈçpublic synchronized void xxx()...
    b.¾²Ì¬·½·¨Í¬²½,ÀýÈçpublic static synchronized void xxx()...
    c.³ÌÐò¿éͬ²½,ÀýÈç
        ...
        synchronized(object oLock)    //×¢Ò⣺object²»Ò»¶¨ÊǸÃÀàµÄʵÀý
        {
            ...
        }
   
    ÔÚÓ÷¨aÖУ¬µ±Ä³Ïß³ÌÖ´Ðз½·¨xxxʱ£¬jvm»áËø¶¨¸ÃÀàµÄʵÀý£¬Ö±µ½·½·¨xxxÖ´ÐÐÍê±Ï¡£Ö´ÐÐxxxµÄ¹ý³Ì¿´¿´³ÉÊÇÕâÑùµÄ£º
    *ÇëÇóµÃµ½ÀàʵÀýµÄʵÀýËø£¬¼ÙÈçÓÐÆäËûÏß³ÌÔÚÖ´ÐУ¬ÔòµÈ´ý£»
    *µÃµ½ÊµÀýËø£¬Ö´ÐÐxxx£»
    *Ö´ÐÐÍê±Ï£¬ÊÍ·ÅʵÀýËø£»
    ×¢Ò⣬Õâ¸ö¹ý³ÌÊÇjvmÍê³ÉµÄ£¬ÎÒÃÇÖ»ÐèÒª°Ñij¸ö¶ÔÏó·½·¨ÉùÃ÷Ϊsynchronized¼´¿É£¬ÊµÀýËø¿ÉÒÔÀí½âΪʵÀý±¾Éí¡£
   
ÔÚÓ÷¨bÖÐ,µ±Ä³Ïß³ÌÖ´Ðо²Ì¬·½·¨xxxʱ£¬Ò²ÊÇÓÐjvm¿ØÖƾ­¹ýÒÔÉϵÄ3¸ö²½Ö裬Ëù²»Í¬µÄÊÇÓÉÓÚ´Ëʱ²»´æÔÚÀàʵÀý£¨¾²Ì¬·½·¨Â£¬Ëù
ÒÔÓ÷¨aÖÐʵÀýËø±»ÊµÀýµÄÀàµÄËøÈ¡´ú£¬Æäʵ¶ÔÎÒÃDZà³ÌÀ´½²£¬¼¸ºõûÓÐÈκÎÇø±ð£¬ÎÒÃÇÖ»ÐèÒª°Ñ¾²Ì¬·½·¨ÉùÃ÷Ϊsynchronized¼´¿É¡£
    ÔÚÓ÷¨cÖУ¬oLock¿ÉÒÔ±»Àí½âΪһ¸ö´«½Ó°ô£¬Ëü¿ÉÒÔÊÇÈκÎÀàµÄʵÀý£¬µ±Ä³¸öÏß³ÌÊÔͼ·ÃÎÊÉùÃ÷ΪsynchronizedµÄ³ÌÐò¿éµÄʱºò£¬jvm
ÅжÏoLockÊÇ·ñ±»Ëø¶¨£¬¼ÙÈçûÓб»Ëø¶¨£¬ÔòËø¶¨oLock²¢Ö´ÐиóÌÐò¿é¡£Ö´ÐÐÍê±ÏÊͷŸÃËø¡£
    ÔÚ¶ÔÏó¼¶Ê¹ÓÃËø£¨ÊµÀýËø£©Í¨³£ÊÇÒ»ÖֱȽϴֲڵķ½·¨£¬ÉèÏëһϣ¬¼ÙÈçÒ»¸ö¶ÔÏó¿ÉÄÜÈ¥·ÃÎÊN¸ö¹²Ïí×ÊÔ´£¬ÄÇô¼ÙÈçÓÐÒ»¸öÏ̶߳ÀÕ¼
Á˸öÔÏ󣬶ø½ö½öÊÇΪÁËʹÓÃÆäÖеÄÒ»Ïî×ÊÔ´µÄ»°£¬Ò²»áÔì³ÉÏë·ÃÎÊÆäËü×ÊÔ´µÄÏß³ÌÒ²´¦ÓÚ¶ÂÈû״̬¡£ÓóÌÐò¿éͬ²½¿ÉÒԺܺýâ¾öÕâ¸öÎÊÌ⣬
ÒÔÏÂÊÇʹÓñ»³ÆΪFine_Grain_LockµÄÀý×Ó£¬¿´£¬Ð§¹ûÊDz»ÊǺÜhigh£º
Java´úÂë
class FineGrainLock {   
       MyMemberClass x, y;   
    Object xlock&


Ïà¹ØÎĵµ£º

JAVAÖÐÓÃÓÚ´¦Àí×Ö·û´®µÄ¡°ÈýÐֵܡ±

JAVAÖÐÓÃÓÚ´¦Àí×Ö·û´®µÄ“ÈýÐֵܔ
JAVAÖÐÓÃÓÚ´¦Àí×Ö·û´®³£ÓõÄÓÐÈý¸öÀࣺjava.lang.String¡¢java.lang.StringBuffer¡¢java.lang.StringBuilder£¬ÕâÈýÕߵĹ²Í¬Ö®´¦¶¼ÊÇfinalÀ࣬²»ÔÊÐí±»¼Ì³Ð£¬ÕâÖ÷ÒªÊÇ´ÓÐÔÄܺͰ²È«ÐÔÉÏ¿¼Âǵģ¬ÒòΪÕ⼸¸öÀ඼ÊǾ­³£±»Ê¹ÓÃ×ŵģ¬ÇÒ¿¼Âǵ½·ÀÖ¹ÆäÖеIJÎÊý±»ÐÞ¸ÄÓ°Ïìµ½ÆäËüµÄÓ¦Óᣠ......

Javaͬ²½»úÖÆ£ºsychronized¶Ô´úÂëÓ°Ïì

ת £ºhttp://kuru.javaeye.com/blog/288467
Java¶Ô¶àÏ̵߳ÄÖ§³ÖÓëͬ²½»úÖÆÉîÊÜ´ó¼ÒµÄϲ°®£¬Ëƺõ¿´ÆðÀ´Ê¹ÓÃÁËsynchronized¹Ø¼ü×־ͿÉÒÔÇáËɵؽâ¾ö¶àÏ̹߳²ÏíÊý¾Ýͬ²½ÎÊÌâ¡£µ½µ×ÈçºÎ£¿¨D¨D»¹µÃ¶Ôsynchronized¹Ø¼ü×ÖµÄ×÷ÓýøÐÐÉîÈëÁ˽â²Å¿É¶¨ÂÛ¡£ ×ܵÄ˵À´£¬synchronized¹Ø¼ü×Ö¿ÉÒÔ×÷Ϊº¯ÊýµÄÐÞÊηû£¬Ò²¿É×÷Ϊº¯ÊýÄÚµÄÓï¾ä£¬Ò ......

javaʵÏÖµÄFTPÉÏ´«ÏÂÔØ¿Í»§¶Ë

org.apache.commons.net.ftp.*ÖеÄFTPClientÀàʵÏÖµÄFTPÉÏ´«ÏÂÔع¦ÄÜ£º
Ðèµ¼ÈëApacheµÄcommos-netµÄjar°ü£¬Èôµ¼ÈëµÄÊÇ1.4°æ±¾µÄ°ü£¬ÔòFTPFile[] fileList = ftpClient.listFiles()µÄÖ´Ðйý³ÌÖпÉÄܻᱨ´í£¬´Ëʱ¸ü»»µ¼Èë2.0°æ±¾µÄjar°ü£¬ÎÊÌâ¼´¿É½â¾ö¡£
´úÂëÈçÏ£º
package com.java.ftp;
import java.io.File;
import ......

JavaµÄAWT

AWTÊÇJavaÖÐÖ§³ÖͼÐλ¯Óû§½çÃæGUIÉè¼ÆµÄÒ»¸ö¹¤¾ß¼¯¡£AWTµÄAPIÊǶÀÁ¢ÓÚƽ̨µÄ£¬µ«Éè¼Æ³öÀ´µÄ½çÃæÔÚ¸÷ÖÖƽ̨µÄ·ç¸ñ²»Í¬£¬ÀûÓÃAPIÖи÷ÖÖÀàÔÚÌض¨Æ½Ì¨ÏµĶԵÈ×é¼þpeersÌṩ¾ßÌåƽ̨ϵÄʵÏÖ¡£
Óû½¨Á¢Ò»¸öGUIÊ×ÏÈÈ·¶¨ËùÓõÄ×é¼þ¼°Æä²¼¾Ö£¬È»ºóʵÏÖÆäʼþµÄÏìÓ¦¡£×é¼þµÄÀàÐÍÓжàÖÖ£¬Èç³£ÓõÄButton¡¢CheckBoxµÈ£¬¾ùΪComponent ......

JavaÖÐByteÐÍת×Ö·û´®

public static String byteToString(byte src)
{
    String desc = null;
    int i = 0;    //È¡1¸ö×Ö½Ú
    i = src&0xFF;
    desc = Integer.toHexString(i);
    if (desc.length() == 1) ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ