Java ¶àÏ̱߳à³ÌÖ®Èý£ºsynchronized ¹Ø¼ü×ÖµÄʹÓÃ
Java ¶àÏ̱߳à³ÌÖ®Èý£ºsynchronized ¹Ø¼ü×ÖµÄʹÓÃ
´øÓÐ synchronized ¹Ø¼ü×ֵķ½·¨´ú±íÕâ¸ö·½·¨¼ÓËø¡£Ç¡µ±¶øÓÖÁé»îµØÔËÓà synchronized ¹Ø¼ü×Ö£¬ÊǶàÏ̱߳à³ÌµÄ±ØÐ޿Ρ£
¡¡¡¡1¡¢synchronized¹Ø¼ü×ÖµÄ×÷ÓÃÓòÓжþÖÖ£º
¡¡¡¡1£©ÊÇij¸ö¶ÔÏóʵÀýÄÚ£¬synchronized aMethod(){}¿ÉÒÔ·ÀÖ¹¶à¸öÏß³Ìͬʱ·ÃÎÊÕâ¸ö¶ÔÏóµÄsynchronized·½·¨£¨Èç¹ûÒ»¸ö¶ÔÏóÓжà¸ösynchronized·½·¨£¬Ö»ÒªÒ»¸öÏ̷߳ÃÎÊÁËÆäÖеÄÒ»¸ösynchronized·½·¨£¬ÆäËüÏ̲߳»ÄÜͬʱ·ÃÎÊÕâ¸ö¶ÔÏóÖÐÈκÎÒ»¸ösynchronized·½·¨£©¡£Õâʱ£¬²»Í¬µÄ¶ÔÏóʵÀýµÄ synchronized·½·¨ÊDz»Ïà¸ÉÈŵġ£Ò²¾ÍÊÇ˵£¬ÆäËüÏß³ÌÕÕÑù¿ÉÒÔͬʱ·ÃÎÊÏàͬÀàµÄÁíÒ»¸ö¶ÔÏóʵÀýÖеÄsynchronized·½·¨£»
¡¡¡¡2£©ÊÇij¸öÀàµÄ·¶Î§£¬synchronized static aStaticMethod(){}·ÀÖ¹¶à¸öÏß³Ìͬʱ·ÃÎÊÕâ¸öÀàÖеÄsynchronized static ·½·¨¡£Ëü¿ÉÒÔ¶ÔÀàµÄËùÓжÔÏóʵÀýÆð×÷Óá£
¡¡¡¡2¡¢³ýÁË·½·¨Ç°ÓÃsynchronized¹Ø¼ü×Ö£¬synchronized¹Ø¼ü×Ö»¹¿ÉÒÔÓÃÓÚ·½·¨ÖеÄij¸öÇø¿éÖУ¬±íʾֻ¶ÔÕâ¸öÇø¿éµÄ×ÊԴʵÐл¥³â·ÃÎÊ¡£Ó÷¨ÊÇ: synchronized(this){/*Çø¿é*/}£¬ËüµÄ×÷ÓÃÓòÊǵ±Ç°¶ÔÏó¡£
synchronized(this)ÓÃÓÚ¶¨ÒåÒ»¸öÁÙ½çÇø£¨¼´ÊÇ£ºÆäºóÃæ´óÀ¨»¡Ëù°üº¬µÄ²¿·Ö£©£¬ÒÔ±£Ö¤ÔÚ¶àÏß³ÌÏÂÖ»ÄÜÓÐÒ»¸öÏ߳̿ÉÒÔ½øÈëthis¶ÔÏóµÄÁÙ½çÇø¡£ Ò²¾ÍÊÇ˵synchronized(¶ÔÏó»òÕß±äÁ¿){}£¬±íʾÔÚ{}ÄÚµÄÕâ¶Î´úÂëÖУ¬¶Ô£¨¶ÔÏó»òÕß±äÁ¿£©ÖеĶÔÏó»òÕß±äÁ¿½øÐÐͬ²½´¦Àí£¬Ò²¾ÍÊÇ˵µ±·ÃÎÊÕâ¶Î´úÂëʱ£¬Ò»¸öÏ̶߳ԶÔÏó»òÕß±äÁ¿µÄ·ÃÎÊÍê³Éºó²ÅÄܹ»½»¸øÁíÍâÒ»¸öỊ̈߳¬¼´ÓÐÁËͬ²½Ëø¡£Ê¹Óà synchronized(¶ÔÏó»òÕß±äÁ¿)£¬¾ÍÊÇΪÁË·ÀÖ¹¶ÔÏó»òÕß±äÁ¿±»Í¬Ê±·ÃÎÊ£¬±ÜÃâ¶à¸öÏß³ÌÐ޸ĺͶÁÈ¡¶ÔÏó»òÕß±äÁ¿Í¬Ê±³öÏÖµÄʱºò£¬Ê¹ÓÃÕâ¸ö¶ÔÏó»òÕß±äÁ¿µÄµØ·½³öÏÖ´íÎóµÄÅжϣ¬Èç while(¶ÔÏó»òÕß±äÁ¿)¡£
¡¡¡¡3¡¢synchronized¹Ø¼ü×ÖÊDz»Äܼ̳еģ¬Ò²¾ÍÊÇ˵£¬»ùÀàµÄ·½·¨synchronized f(){} Ôڼ̳ÐÀàÖв¢²»×Ô¶¯ÊÇsynchronized f(){}£¬¶øÊDZä³ÉÁËf(){}¡£¼Ì³ÐÀàÐèÒªÄãÏÔʽµÄÖ¸¶¨ËüµÄij¸ö·½·¨Îªsynchronized·½·¨¡£
Ïà¹ØÎĵµ£º
repaint ¶Ô×é¼þ½øÐÐÖØ»æ£¬±ÈÈçÒ»¸öpanel£¬µ±ÄãremoveµôpanelÀïÃæµÄÒ»¸ö×é¼þʱ£¬Äã±ØÐëµ÷ÓÃrepaint·½·¨²ÅÄܶÔpanel½øÐÐÖØ»æ£¬½øÐÐˢУ¬ÄãÏëҪɾ³ýµÄ×é¼þ²ÅÄÜÔÚ½çÃæÉÏÏûʧ¡£
revalidate ¶Ô×é¼þ½øÐÐÑéÖ¤£¬±ÈÈçÒ»¸öpanel£¬µ±ÄãremoveµôpanelÀïÃæµÄÒ»¸ö×é¼þʱ£¬µ±Äãµ÷ÓÃrevalidate·½·¨ºó£¬panelµÄ²¼ ......
synchronizedµÄÒ»¸ö¼òµ¥Àý×Ó
public class TextThread
{
/**
* @param args
*/
public static void main(String[] args)
{
// TODO ×Ô¶¯Éú³É·½·¨´æ¸ù
TxtThread tt = new TxtThread();
  ......
javaÖеÄʼþ»úÖÆµÄ²ÎÓëÕßÓÐ3ÖÖ½ÇÉ«£º
1.event object£º¾ÍÊÇʼþ²úÉúʱ¾ßÌåµÄ“ʼþ”£¬ÓÃÓÚlistenerµÄÏàÓ¦µÄ·½·¨Ö®ÖУ¬×÷Ϊ²ÎÊý£¬Ò»°ã´æÔÚÓëlisternerµÄ·½·¨Ö®ÖÐ
2.event source£º¾ßÌåµÄ½ÓÊÜʼþµÄʵÌ壬±ÈÈç˵£¬Äãµã»÷Ò»¸öbutton£¬ÄÇôbutton¾ÍÊÇevent source£¬ÕâÑùÄã±ØÐëʹbutton¶ÔijЩʼþ½øÐÐÏàÓ¦£¬Äã¾ÍÐè ......
×ªÔØ×Ôhttp://blog.csdn.net/yuekun1172006/archive/2007/06/02/1634878.aspx
Àà×°ÈëÆ÷ÊÇ JVM ÓÃÀ´×°ÈëÀàµÄÀ࣬Ëü¶ÔÓÚ Java ±à³ÌÊǷdz£ÖØÒªµÄÒ»¸ö¸ÅÄî¡£Ò»°ãÇé¿öÏ£¬³ÌÐòÔ±ÔÚ±àд³ÌÐòµÄʱºò¶¼¿ÉÒÔºöÂÔÀà×°ÈëÆ÷µÄ´æÔÚÐÔ¡£µ«ÊǶÔÓÚ·þÎñÆ÷¶Ë±à³Ì»òÕßÊÇÒ»Ð©ÌØÊâÇé¿öÏÂʱºò£¬ÉîÈëÁ˽âÀà×°ÈëÆ÷µÄ»úÖÆÒÔ¼°ÆäÔÚ²»Í¬Çé¿öϵ ......
java·ÃÎÊ¡£netµÄwebservice ¶øÇÒ ·µ»ØÖµÊÇÒ»¸öÀ࣬ÕâÍæÒâÕÛÄ¥ÎÒÒ»Ì죬³öÏÖ¹ýһϵÁеÄÎÊÌ⣬
°üÀ¨ ûÓж¨ÒåSoapAction ²»ÄÜÐòÁл¯ÀàµÈµÈ¡£ ×îºó»¹ÊÇ·þÎñÌṩÉ̸øÁ˸ödemo£¬½â¾öÁË £¬ÔÒòÊÇÎÒ·µ»Ø×Ô¶¨ÒåÀàµÄÒ»¸ö±äÁ¿Ã»ÓÐgetº¯Êý£¬¿É³Ü°¡¡£¶øÇÒdemoÀïµÄ´úÂë ÎÒÏëÒ²ÊÇÓÃwsdd2javaÉú³ÉµÄ£¬ÎÒÒÔǰҲ¿´µ½¹ýÕâÖÖģʽµÄʵÏÖ£¬¿´×Å·Ñ ......