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

JavaỊ̈߳ºvolatile¹Ø¼ü×Ö

JavaỊ̈߳ºvolatile¹Ø¼ü×Ö
 
Java™ ÓïÑÔ°üº¬Á½ÖÖÄÚÔÚµÄͬ²½»úÖÆ£ºÍ¬²½¿é£¨»ò·½·¨£©ºÍ volatile ±äÁ¿¡£ÕâÁ½ÖÖ»úÖƵÄÌá³ö¶¼ÊÇΪÁËʵÏÖ´úÂëÏ̵߳ݲȫÐÔ¡£ÆäÖÐ Volatile ±äÁ¿µÄͬ²½ÐԽϲµ«ÓÐʱËü¸ü¼òµ¥²¢ÇÒ¿ªÏú¸üµÍ£©£¬¶øÇÒÆäʹÓÃÒ²¸üÈÝÒ׳ö´í¡£
 
̸¼°µ½volatile¹Ø¼ü×Ö£¬²»µÃ²»ÌáµÄһƪÎÄÕÂÊÇ£º¡¶Java ÀíÂÛÓëʵ¼ù: ÕýȷʹÓà Volatile ±äÁ¿¡·£¬ÕâƪÎÄÕ¶Ôvolatile¹Ø¼ü×ÖµÄÓ÷¨×öÁËÏ൱¾«±ÙµÄ²ûÊö¡£
 
Ö®ËùÒÔÒªµ¥¶ÀÌá³övolatileÕâ¸ö²»³£ÓõĹؼü×ÖÔ­ÒòÊÇÕâ¸ö¹Ø¼ü×ÖÔÚ¸ßÐÔÄܵĶàÏ̳߳ÌÐòÖÐÒ²ÓкÜÖØÒªµÄÓÃ;£¬Ö»ÊÇÕâ¸ö¹Ø¼ü×ÖÓò»ºÃ»á³öºÜ¶àÎÊÌâ¡£
 
Ê×ÏÈ¿¼ÂÇÒ»¸öÎÊÌ⣬Ϊʲô±äÁ¿ÐèÒªvolatileÀ´ÐÞÊÎÄØ£¿
Òª¸ãÇå³þÕâ¸öÎÊÌ⣬Ê×ÏÈÓ¦¸ÃÃ÷°×¼ÆËã»úÄÚ²¿¶¼×öʲôÁË¡£±ÈÈç×öÁËÒ»¸öi++²Ù×÷£¬¼ÆËã»úÄÚ²¿×öÁËÈý´Î´¦Àí£º¶ÁÈ¡£­Ð޸ģ­Ð´Èë¡£
ͬÑù£¬¶ÔÓÚÒ»¸ölongÐÍÊý¾Ý£¬×öÁ˸ö¸³Öµ²Ù×÷£¬ÔÚ32ϵͳÏÂÐèÒª¾­¹ýÁ½²½²ÅÄÜÍê³É£¬ÏÈÐ޸ĵÍ32λ£¬È»ºóÐ޸ĸß32λ¡£
 
¼ÙÏëһϣ¬µ±½«ÒÔÉϵIJÙ×÷·Åµ½Ò»¸ö¶àÏ̻߳·¾³Ï²Ù×÷ʱºò£¬ÓпÉÄܳöÏÖµÄÎÊÌ⣬ÊÇÕâЩ²½ÖèÖ´ÐÐÁËÒ»²¿·Ö£¬¶øÁíÍâÒ»¸öÏ߳̾ÍÒѾ­ÒýÓÃÁ˱äÁ¿Öµ£¬ÕâÑù¾Íµ¼ÖÂÁ˶ÁÈ¡ÔàÊý¾ÝµÄÎÊÌâ¡£
 
ͨ¹ýÕâ¸öÉèÏ룬¾Í²»ÄÑÀí½âvolatile¹Ø¼ü×ÖÁË¡£
 
volatile¿ÉÒÔÓÃÔÚÈκαäÁ¿Ç°Ã棬µ«²»ÄÜÓÃÓÚfinal±äÁ¿Ç°Ã棬ÒòΪfinalÐ͵ıäÁ¿ÊǽûÖ¹Ð޸ĵġ£Ò²²»´æÔÚḬ̈߳²È«µÄÎÊÌâ¡£
 
¸ü¶àµÄÄÚÈÝ£¬Çë²Î¿´£º£º¡¶Java ÀíÂÛÓëʵ¼ù: ÕýȷʹÓà Volatile ±äÁ¿¡·Ò»ÎÄ£¬Ð´µÃºÜºÃ¡£
 


Ïà¹ØÎĵµ£º

ʹÓÃeclipseÔËÐÐÔø¾­Ð´¹ýµÄjava´úÂë

½ñÌì°ÑÒÔǰдµÄjava´úÂëÄóöÀ´£¬·¢ÏÖ³öÁ˺öà´íÎó¡£µ÷ÁË°ëÌ죬·¢ÏÖÊÇ°æ±¾µÄÎÊÌ⣬ÓôÃÆ£¡
¿ÉÄÜ֮ǰÎÒд´úÂëµÄʱºòÓõÄÊÇJDK1.5£¬½ñÌì´ÓÍøÉÏÏÂÔØJDK1.6£¬Ã»³É¹¦¡£¾Í²Ý²ÝÏÂÔØÁËJDK1.5,½á¹û×ÜÊÇÌáʾ“could not find the main class. program will exit”¡£ÎҾ͵½
window-¡·preference-¡·java-¡·compiler°Ñµ±Ç°µÄ°æ ......

JavaỊ̈߳º¸ÅÄîÓëÔ­Àí

JavaỊ̈߳º¸ÅÄîÓëÔ­Àí
 
SCJP5ѧϰ±Ê¼Ç
 
Ò»¡¢²Ù×÷ϵͳÖÐÏ̺߳ͽø³ÌµÄ¸ÅÄî
ÏÖÔڵIJÙ×÷ϵͳÊǶàÈÎÎñ²Ù×÷ϵͳ¡£¶àÏß³ÌÊÇʵÏÖ¶àÈÎÎñµÄÒ»ÖÖ·½Ê½¡£
½ø³ÌÊÇÖ¸Ò»¸öÄÚ´æÖÐÔËÐеÄÓ¦ÓóÌÐò£¬Ã¿¸ö½ø³Ì¶¼ÓÐ×Ô¼º¶ÀÁ¢µÄÒ»¿éÄÚ´æ¿Õ¼ä£¬Ò»¸ö½ø³ÌÖпÉÒÔÆô¶¯¶à¸öÏ̡߳£±ÈÈçÔÚWindowsϵͳÖУ¬Ò»¸öÔËÐеÄexe¾ÍÊÇÒ»¸ö½ø³Ì¡£
&nb ......

JavaỊ̈߳ºÏ̵߳ĵ÷¶È Èò½

JavaỊ̈߳ºÏ̵߳ĵ÷¶È-Èò½
 
Ï̵߳ÄÈò½º¬Òå¾ÍÊÇʹµ±Ç°ÔËÐÐ×ÅÏß³ÌÈóöCPU×ÊÔ´£¬µ«ÊÇÈ»¸øË­²»ÖªµÀ£¬½ö½öÊÇÈóö£¬Ïß³Ì״̬»Øµ½¿ÉÔËÐÐ״̬¡£
 
Ï̵߳ÄÈò½Ê¹ÓÃThread.yield()·½·¨£¬yield() Ϊ¾²Ì¬·½·¨£¬¹¦ÄÜÊÇÔÝÍ£µ±Ç°ÕýÔÚÖ´ÐеÄÏ̶߳ÔÏ󣬲¢Ö´ÐÐÆäËûÏ̡߳£
 
/**
* JavaỊ̈߳ºÏ̵߳ĵ÷¶È-Èò½
*
......

JavaỊ̈߳ºÏ̵߳ĵ÷¶È ÊØ»¤Ïß³Ì

JavaỊ̈߳ºÏ̵߳ĵ÷¶È-ÊØ»¤Ïß³Ì
 
ÊØ»¤Ïß³ÌÓëÆÕͨÏß³Ìд·¨ÉÏ»ù±¾Ã´É¶Çø±ð£¬µ÷ÓÃÏ̶߳ÔÏóµÄ·½·¨setDaemon(true)£¬Ôò¿ÉÒÔ½«ÆäÉèÖÃΪÊØ»¤Ï̡߳£
 
ÊØ»¤Ïß³ÌʹÓõÄÇé¿ö½ÏÉÙ£¬µ«²¢·ÇÎÞÓ㬾ÙÀýÀ´Ëµ£¬JVMµÄÀ¬»ø»ØÊÕ¡¢ÄÚ´æ¹ÜÀíµÈÏ̶߳¼ÊÇÊØ»¤Ï̡߳£»¹ÓоÍÊÇÔÚ×öÊý¾Ý¿âÓ¦ÓÃʱºò£¬Ê¹ÓõÄÊý¾Ý¿âÁ¬½Ó³Ø£¬Á¬½Ó³Ø±¾ÉíÒ²°üº ......

JavaỊ̈߳º²¢·¢Ð­×÷ Éú²úÕßÏû·ÑÕßÄ£ÐÍ

JavaỊ̈߳º²¢·¢Ð­×÷-Éú²úÕßÏû·ÑÕßÄ£ÐÍ
 
¶ÔÓÚ¶àÏ̳߳ÌÐòÀ´Ëµ£¬²»¹ÜÈκαà³ÌÓïÑÔ£¬Éú²úÕߺÍÏû·ÑÕßÄ£ÐͶ¼ÊÇ×î¾­µäµÄ¡£¾ÍÏñѧϰÿһÃűà³ÌÓïÑÔÒ»Ñù£¬Hello World£¡¶¼ÊÇ×î¾­µäµÄÀý×Ó¡£
 
ʵ¼ÊÉÏ£¬×¼È·ËµÓ¦¸ÃÊÇ“Éú²úÕß-Ïû·ÑÕß-²Ö´¢”Ä£ÐÍ£¬À뿪Á˲ִ¢£¬Éú²úÕßÏû·ÑÕßÄ£Ð;ÍÏÔµÃûÓÐ˵·þÁ¦ÁË¡£
¶ÔÓÚ´ËÄ£ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ