java ÖÐµÄ synchronized
synchronized£º ͬ²½µÄ
synchronizedÔÚ²Ù×÷ÉÏÓÐÁ½ÖÖÓ°Ïì¶ÔÏóµÄÇé¿ö£º
1) ÔÚij¸ö¶ÔÏóʵÀýÄÚ£¬synchronized method(){}¿ÉÒÔ·ÀÖ¹¶à¸öÏß³Ìͬʱ·ÃÎÊÕâ¸ö¶ÔÏóµÄsynchronized·½·¨£¨Èç¹ûÒ»¸ö¶ÔÏóÓжà¸ösynchronized·½·¨£¬Ö»ÒªÒ»¸öÏ̷߳ÃÎÊÁËÆäÖеÄÒ»¸ösynchronized·½·¨£¬ÆäËüÏ̲߳»ÄÜͬʱ·ÃÎÊÕâ¸ö¶ÔÏóÖÐÈκÎÒ»¸ösynchronized·½·¨£©¡£Õâʱ£¬²»Í¬µÄ¶ÔÏóʵÀýµÄsynchronized·½·¨ÊDz»Ïà¸ÉÈŵġ£Ò²¾ÍÊÇ˵£¬ÆäËüÏß³ÌÕÕÑù¿ÉÒÔͬʱ·ÃÎÊÏàͬÀàµÄÁíÒ»¸ö¶ÔÏóʵÀýÖеÄsynchronized·½·¨£»
2) ÔÚij¸öÀàµÄ·¶Î§£¬synchronized static aStaticMethod{}·ÀÖ¹¶à¸öÏß³Ìͬʱ·ÃÎÊÕâ¸öÀàÖеÄsynchronized static ·½·¨¡£Ëü¿ÉÒÔ¶ÔÀàµÄËùÓжÔÏóʵÀýÆð×÷Óá£
³ýÁË·½·¨Ç°ÓÃsynchronized¹Ø¼ü×Ö£¬synchronized¹Ø¼ü×Ö»¹¿ÉÒÔÓÃÓÚ·½·¨ÖеÄij¸öÇø¿éÖУ¬±íʾֻ¶ÔÕâ¸öÇø¿éµÄ×ÊԴʵÐл¥³â·ÃÎÊ¡£Ó÷¨ÊÇ: synchronized(this){/*Çø¿é*/}£¬ËüµÄ×÷ÓÃÓòÊǵ±Ç°¶ÔÏó£»
synchronized¹Ø¼ü×ÖÊDz»Äܼ̳еģ¬Ò²¾ÍÊÇ˵£¬»ùÀàµÄ·½·¨synchronized method(){} Ôڼ̳ÐÀàÖв¢²»×Ô¶¯ÊÇsynchronized method(){}£¬¶øÊDZä³ÉÁËmethod(){}¡£¼Ì³ÐÀàÐèÒªÄãÏÔʽµÄÖ¸¶¨ËüµÄij¸ö·½·¨Îªsynchronized·½·¨£»
ÎÞÂÛsynchronized¹Ø¼ü×Ö¼ÓÔÚ·½·¨ÉÏ»¹ÊǶÔÏóÉÏ£¬ËûÈ¡µÃµÄËø¶¼ÊǶÔÏóËø£¬¶ø²»ÊÇ°ÑÒ»¶Î´úÂë»òº¯ÊýËø¶¨£¬²»Äܱ»±ðµÄ¶ÔÏó·ÃÎÊ£¬Í¬Ò»¸öÀàÖеÄͬһ¸ö·½·¨»áÔÚ¸ÃÀàµÄ²»Í¬¶ÔÏóÉϱ»ÆäËûÏ̵߳ĶÔÏó·ÃÎÊ¡£
ÿ¸ö¶ÔÏóÖ»ÓÐÒ»°ÑËø£¨lock£©ºÍËüÏà¹ØÁª¡£
ʵÏÖͬ²½ÊÇÒªºÜ´óµÄϵͳ¿ªÏú×÷Ϊ´ú¼ÛµÄ£¬ÉõÖÁ¿ÉÄÜÔì³ÉËÀËø£¬ËùÒÔ¾¡Á¿±ÜÃâÎÞνµÄͬ²½¿ØÖÆ¡£
µ«µ±Ã»ÓÐÃ÷È·µÄ¶ÔÏóÐèÒªËø¶¨£¬Ö»ÊÇÏëÈÃÒ»¶Î´úÂëͬ²½Ê±£¬Äܹ»´´½¨Ò»¸öÌرðµÄinstance±äÁ¿£¨ËûµÃÊǸö¶ÔÏó£©À´³äµ±Ëø£º
class Foo implements Runnable {
private byte[] lock = new byte[0]; // ÌرðµÄinstance±äÁ¿
Public void method() {
synchronized(lock) { //… }
}
//…
}
Á㳤¶ÈµÄbyteÊý×é¶ÔÏó´´½¨ÆðÀ´½«±ÈÈκζÔÏ󶼾¼Ã£¬±àÒëºóµÄ×Ö½ÚÂ룺Éú³ÉÁ㳤¶ÈµÄbyte[]¶ÔÏóÖ»Ðè3Ìõ²Ù×÷Â룬¶øObject lock = new Object()ÔòÐèÒª7ÐвÙ×÷Âë¡£
class Foo {
public void method() {
&
Ïà¹ØÎĵµ£º
JavaỊ̈߳ºÐÂÌØÕ÷-Óзµ»ØÖµµÄÏß³Ì
ÔÚJava5֮ǰ£¬Ïß³ÌÊÇûÓзµ»ØÖµµÄ£¬³£³£ÎªÁË“ÓД·µ»ØÖµ£¬ÆÆ·ÑÖÜÕÛ£¬¶øÇÒ´úÂëºÜ²»ºÃд¡£»òÕ߸ɴàÈƹýÕâµÀ¿²£¬×ß±ðµÄ·ÁË¡£
ÏÖÔÚJavaÖÕÓÚÓпɷµ»ØÖµµÄÈÎÎñ£¨Ò²¿ÉÒÔ½Ð×öỊ̈߳©ÁË¡£
¿É·µ»ØÖµµÄÈÎÎñ±ØÐëʵÏÖCallable½Ó¿Ú£¬ÀàËƵģ¬ÎÞ·µ»ØÖµµÄÈÎÎñ±ØÐëRu ......
JavaỊ̈߳ºÐÂÌØÕ÷-Ëø£¨ÉÏ£©
ÔÚJava5ÖУ¬×¨ÃÅÌṩÁËËø¶ÔÏó£¬ÀûÓÃËø¿ÉÒÔ·½±ãµÄʵÏÖ×ÊÔ´µÄ·âËø£¬ÓÃÀ´¿ØÖƶԾºÕù×ÊÔ´²¢·¢·ÃÎʵĿØÖÆ£¬ÕâЩÄÚÈÝÖ÷Òª¼¯ÖÐÔÚjava.util.concurrent.locks °üÏÂÃ棬ÀïÃæÓÐÈý¸öÖØÒªµÄ½Ó¿ÚCondition¡¢Lock¡¢ReadWriteLock¡£
Condition
Condition ½« Object ¼àÊÓÆ÷·½·¨£¨wait¡¢notify ......
Java Éú³É EXCEL POIÎĵµËµÃ÷
POI°æ±¾:3.0.2-FINAL
ÏÂÔصØÖ·: http://poi.apache.org/index.html
Ò»°ãÔÚÏîÄ¿ÖÐÕæÕýҪʵÏÖÕâÑùÒ»¸ö±í¸ñµÄʱºò£¬ÀýÈçÏîÄ¿ÐèÒªÖÆ×÷±¨±íµÈµÈ£¬Í¨³£µÄ×ö·¨¶¼ÊÇÊÂÏȰѸñʽһÇеĶ«Î÷¶¼ÊÖ¶¯ÖÆ×÷ºÃ£¨Õâ¸ö×öºÃÁ˵ÄÎļþÔÚʵ¼ÊµÄÏîÄ¿ÀïÎÒÃdzÆ֮Ϊ“Êý¾ÝÄ£°å”£¬¼ò³Æ“Ä£°å&rd ......
°æȨÉùÃ÷£º×ªÔØʱÇëÒÔ³¬Á´½ÓÐÎʽ±êÃ÷ÎÄÕÂÔʼ³ö´¦ºÍ×÷ÕßÐÅÏ¢¼°±¾ÉùÃ÷
http://as112255.blogbus.com/logs/38662785.html
package com.softeem.jbs.lesson4;
import java.util.Random;
/**
* ÅÅÐò²âÊÔÀà
*
* ÅÅÐòËã·¨µÄ·ÖÀàÈçÏ£º
* 1.²åÈëÅÅÐò£¨Ö±½Ó²åÈëÅÅÐò¡¢ÕÛ°ë²åÈëÅÅÐ ......
ÊäÈëÊä³öÁ÷
ÔÚJavaÖУ¬ÎÒÃÇ°ÑÄܹ»¶ÁÈ¡Ò»¸ö×Ö½ÚÐòÁеĶÔÏó³Æ×÷Ò»¸öÊäÈëÁ÷;¶øÎÒÃǰѹ»Ð´Ò»¸ö×Ö½ÚÐòÁгÆ×÷Ò»¸öÊä³öÁ÷¡£ËüÃÇ·Ö±ðÓɳéÏóÀà InputStreamºÍOutputStreamÀà±íʾ¡£ÒòΪÃæÏò×Ö½ÚµÄÁ÷²»·½±ãÓÃÀ´´¦Àí´æ´¢ÎªUnicode£¨Ã¿¸ö×Ö·ûʹÓÃÁ½¸ö×Ö½Ú)µÄÐÅÏ¢¡£ËùÒÔJavaÒýÈëÁËÓÃÀ´´¦ÀíUnicode×Ö·ûµÄÀà²ã´Î£¬ÕâЩÀàÅÉÉú×Ô³éÏóÀàReade ......