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

java volatile ¹Ø¼ü×Ö

volatile¹Ø¼ü×ÖÓÐʲôÓã¿
¿ÖűȽÏÒ»ÏÂvolatileºÍsynchronizedµÄ²»Í¬ÊÇ×îÈÝÒ×½âÊÍÇå³þµÄ¡£volatileÊDZäÁ¿ÐÞÊηû£¬¶øsynchronizedÔò×÷ÓÃÓÚÒ»¶Î´úÂë»ò·½·¨£»¿´ÈçÏÂÈý¾äget´úÂ룺
int i1;                          int geti1() {return i1;}
volatile int i2;              int geti2() {return i2;}
int i3; synchronized     int geti3() {return i3;}
geti1()µÃµ½´æ´¢ÔÚµ±Ç°Ïß³ÌÖÐi1µÄÊýÖµ¡£¶à¸öÏß³ÌÓжà¸öi1±äÁ¿¿½±´£¬¶øÇÒÕâЩi1Ö®¼ä¿ÉÒÔ»¥²»Ïàͬ¡£»»¾ä»°Ëµ£¬ÁíÒ»¸öÏ߳̿ÉÄÜÒѾ­¸Ä±äÁËËüÏß³ÌÄÚµÄi1Öµ£¬¶øÕâ¸öÖµ¿ÉÒԺ͵±Ç°Ïß³ÌÖеÄi1Öµ²»Ïàͬ¡£ÊÂʵÉÏ£¬JavaÓиö˼Ïë½Ð¡°Ö÷¡±ÄÚ´æÇøÓò£¬ÕâÀï´æ·ÅÁ˱äÁ¿Ä¿Ç°µÄ¡°×¼È·Öµ¡±¡£Ã¿¸öÏ߳̿ÉÒÔÓÐËü×Ô¼ºµÄ±äÁ¿¿½±´£¬¶øÕâ¸ö±äÁ¿¿½±´Öµ¿ÉÒԺ͡°Ö÷¡±ÄÚ´æÇøÓòÀï´æ·ÅµÄ²»Í¬¡£Òò´Ëʵ¼ÊÉÏ´æÔÚÒ»ÖÖ¿ÉÄÜ£º¡°Ö÷¡±ÄÚ´æÇøÓòÀïµÄi1ÖµÊÇ1£¬Ïß³Ì1ÀïµÄi1ÖµÊÇ2£¬Ïß³Ì2ÀïµÄi1ÖµÊÇ3——ÕâÔÚÏß³Ì1ºÍÏß³Ì2¶¼¸Ä±äÁËËüÃǸ÷×ÔµÄi1Öµ£¬¶øÇÒÕâ¸ö¸Ä±ä»¹Ã»À´µÃ¼°´«µÝ¸ø¡°Ö÷¡±ÄÚ´æÇøÓò»òÆäËûÏß³Ìʱ¾Í»á·¢Éú¡£
¶øgeti2()µÃµ½µÄÊÇ¡°Ö÷¡±ÄÚ´æÇøÓòµÄi2ÊýÖµ¡£ÓÃvolatileÐÞÊκóµÄ±äÁ¿²»ÔÊÐíÓв»Í¬ÓÚ¡°Ö÷¡±ÄÚ´æÇøÓòµÄ±äÁ¿¿½±´¡£»»¾ä»°Ëµ£¬Ò»¸ö±äÁ¿¾­volatileÐÞÊκóÔÚËùÓÐÏß³ÌÖбØÐëÊÇͬ²½µÄ£»ÈκÎÏß³ÌÖиıäÁËËüµÄÖµ£¬ËùÓÐÆäËûÏß³ÌÁ¢¼´»ñÈ¡µ½ÁËÏàͬµÄÖµ¡£ÀíËùµ±È»µÄ£¬volatileÐÞÊεıäÁ¿´æȡʱ±ÈÒ»°ã±äÁ¿ÏûºÄµÄ×ÊÔ´Òª¶àÒ»µã£¬ÒòΪÏß³ÌÓÐËü×Ô¼ºµÄ±äÁ¿¿½±´¸üΪ¸ßЧ¡£
¼ÈÈ»volatile¹Ø¼ü×ÖÒѾ­ÊµÏÖÁËÏ̼߳äÊý¾Ýͬ²½£¬ÓÖÒªsynchronized¸ÉʲôÄØ£¿ºÇºÇ£¬ËüÃÇÖ®¼äÓÐÁ½µã²»Í¬¡£Ê×ÏÈ£¬synchronized»ñµÃ²¢ÊͷżàÊÓÆ÷——Èç¹ûÁ½¸öÏß³ÌʹÓÃÁËͬһ¸ö¶ÔÏóËø£¬¼àÊÓÆ÷ÄÜÇ¿ÖƱ£Ö¤´úÂë¿éͬʱֻ±»Ò»¸öÏß³ÌËùÖ´ÐЗ—ÕâÊÇÖÚËùÖÜÖªµÄÊÂʵ¡£µ«ÊÇ£¬synchronizedҲͬ²½Äڴ棺ÊÂʵÉÏ£¬synchronizedÔÚ¡°Ö÷¡±ÄÚ´æÇøÓòͬ²½Õû¸öÏ̵߳ÄÄÚ´æ¡£Òò´Ë£¬Ö´ÐÐgeti3()·½·¨×öÁËÈçϼ¸²½£º
1. Ïß³ÌÇëÇó»ñµÃ¼àÊÓthis¶ÔÏóµÄ¶ÔÏóËø£¨¼ÙÉèδ±»Ëø£¬·ñÔòÏ̵߳ȴýÖ±µ½ËøÊÍ·Å£©
2. Ïß³ÌÄÚ´æµÄÊý¾Ý±»Ïû³ý£¬´Ó¡°Ö÷¡±ÄÚ´æÇøÓòÖжÁÈ루JavaÐéÄâ»úÄÜÓÅ»¯´Ë²½¡£¡£¡£[ºóÃæµÄ²»ÖªµÀÔõô±í´ï,º¹]£©


Ïà¹ØÎĵµ£º

Java ¶ÔÏóÐòÁл¯

Java 1.1ÔöÌíÁËÒ»ÖÖÓÐȤµÄÌØÐÔ£¬ÃûΪ¡°¶ÔÏóÐòÁл¯¡±£¨Object Serialization£©¡£ËüÃæÏòÄÇЩʵÏÖÁËSerializable½Ó¿ÚµÄ¶ÔÏ󣬿ɽ«ËüÃÇת»»³ÉһϵÁÐ×Ö½Ú£¬²¢¿ÉÔÚÒÔºóÍêÈ«»Ö¸´»ØÔ­À´µÄÑù×Ó¡£ÕâÒ»¹ý³ÌÒà¿Éͨ¹ýÍøÂç½øÐС£ÕâÒâζ×ÅÐòÁл¯»úÖÆÄÜ×Ô¶¯²¹³¥²Ù×÷ϵͳ¼äµÄ²îÒì¡£»»¾ä»°Ëµ£¬¿ÉÒÔÏÈÔÚWindows»úÆ÷ÉÏ´´½¨Ò»¸ö¶ÔÏ󣬶ÔÆäÐòÁл¯£ ......

ËĸöÓꦵÄJava±àÂëÏ°¹ß

³ÌÐòÖеıàÂë·ç¸ñÈÃÎÒÃǵıà³Ì¹¤×÷±äµÃÇáËÉ£¬ÌرðÊdzÌÐòά»¤Ô±£¬ËûÃÇÒª¾­³£ÔĶÁÆäËûÈ˱àдµÄ³ÌÐò±àÂ룬ÕâÒ»µãÓÈÆäÍ»³ö¡£±àÂë¹æ·¶´Ó¸ù±¾ÉϽâ¾öÁ˳ÌÐòά»¤Ô±µÄÄÑÌ⣻¹æ·¶µÄ±àÂëÔĶÁºÍÀí½âÆðÀ´¸üÈÝÒ×£¬Ò²¿ÉÒÔ¿ìËٵIJ»·ÑÁ¦ÆøµÄ½è¼ø±ðÈ˵ıàÂë¡£¶Ô½«À´Î¬»¤Äã±àÂëµÄÈËÀ´Ëµ£¬ÄãµÄ±àÂëÔ½ÓÅ»¯£¬ËûÃǾÍԽϲ»¶ÄãµÄ±àÂ룬Àí½âÆðÀ´Ò²¾ÍÔ½ ......

JAVAðÅÝÅÅÐòËã·¨µÄ¼¸ÖÖʵÏÖ·½·¨

±¾Îijö×Ô “ÌÆ´óÀÏʦ” ²©¿Í£¬ÇëÎñ±Ø±£Áô´Ë³ö´¦http://tscjsj.blog.51cto.com/412451/84561
public class Bubble {
// ðÅÝÅÅÐòº¯Êý1
public static void bubbleSort1(Comparable []data){

int position,scan;
Comparable temp;
for(position = data.length-1;position>=0;position--){
......

javaÖÐStringÀàµÄ¹¹Ô캯Êý

StringÀàÖеĹ¹Ô캯Êý
String(); ¹¹ÔìÒ»¸ö¿Õ×Ö·û´®¶ÔÏó
String(byte[] bytes); ͨ¹ýbyteÊý×é¹¹Ôì×Ö·û´®¶ÔÏó
String(byte[] bytes,int offset,int length);ͨ¹ýbyteÊý×飬´Óoffset¿ªÊ¼£¬×ܹ²length³¤µÄ×Ö½Ú¹¹Ôì×Ö·û´®¶ÔÏó
String(char[] value); ͨ¹ýcharÊý×é¹¹Ôì×Ö·û´®¶ÔÏó
String(byte[] char,int offset,int length) ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ