dz̸Java¶àÏ̵߳Äͬ²½ÎÊÌâ
¶àÏ̵߳Äͬ²½ÒÀ¿¿µÄÊǶÔÏóËø»úÖÆ£¬synchronized¹Ø¼ü×ֵı³ºó¾ÍÊÇÀûÓÃÁË·âËøÀ´ÊµÏÖ¶Ô¹²Ïí×ÊÔ´µÄ»¥³â·ÃÎÊ¡£
ÏÂÃæÒÔÒ»¸ö¼òµ¥µÄʵÀýÀ´½øÐжԱȷÖÎö¡£ÊµÀýÒªÍê³ÉµÄ¹¤×÷·Ç³£¼òµ¥£¬¾ÍÊÇ´´½¨10¸öỊ̈߳¬Ã¿¸öÏ̶߳¼´òÓ¡´Ó0µ½99Õâ100¸öÊý×Ö£¬ÎÒÃÇÏ£ÍûÏß³ÌÖ®¼ä²»»á³öÏÖ½»²æÂÒÐò´òÓ¡£¬¶øÊÇ˳ÐòµØ´òÓ¡¡£
ÏÈÀ´¿´µÚÒ»¶Î´úÂ룬ÕâÀïÎÒÃÇÔÚrun()·½·¨ÖмÓÈëÁËsynchronized¹Ø¼ü×Ö£¬Ï£ÍûÄܶÔrun·½·¨½øÐл¥³â·ÃÎÊ£¬µ«½á¹û²¢²»ÈçÎÒÃÇÏ£ÍûÄÇÑù£¬ÕâÊÇÒòΪÕâÀïsynchronizedËø×¡µÄÊÇthis¶ÔÏ󣬼´µ±Ç°ÔËÐÐÏ̶߳ÔÏó±¾Éí¡£´úÂëÖд´½¨ÁË10¸öỊ̈߳¬¶øÃ¿¸öÏ̶߳¼³ÖÓÐthis¶ÔÏóµÄ¶ÔÏóËø£¬Õâ²»ÄÜʵÏÖÏ̵߳Äͬ²½¡£´úÂëpackage com.vista;
class MyThread implements java.lang.Runnable
{
private int threadId;
public MyThread(int id)
{
this.threadId = id;
}
@Override
public synchronized void run()
{
for (int i = 0; i < 100; ++i)
{
System.out.println("Thread ID: " + this.threadId + " : " + i);
}
}
}
public class ThreadDemo
{
/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException
{
for (int i = 0; i < 10; ++i)
&nbs
Ïà¹ØÎĵµ£º
ѧϰJava±Ø¿´ - JAVA´úÂë±àдµÄ30Ìõ½¨Òé
(1) ÀàÃûÊ××ÖĸӦ¸Ã´óд¡£×ֶΡ¢·½·¨ÒÔ¼°¶ÔÏ󣨾ä±ú£©µÄÊ××ÖĸӦСд¡£¶ÔÓÚËùÓбêʶ·û£¬ÆäÖаüº¬µÄËùÓе¥´Ê¶¼Ó¦½ô¿¿ÔÚÒ»Æð£¬¶øÇÒ´óдÖм䵥´ÊµÄÊ××Öĸ¡£ÀýÈ磺
ThisIsAClassName
thisIsMethodOrFieldName
ÈôÔÚ¶¨ÒåÖгöÏÖÁ˳£Êý³õʼ»¯ ......
½ñÄêÒѾ28ËêÁË Í»È»·¢ÏÖÒѾºÜ²»Ï°¹ß±àд´úÂëÁË£¬µ«ÊǶԳÌÐòÖÐËùÓеĴíÎóºÍÀ§ÄÑ£¬¶¼ÄÜºÜÆ½¾²µÄÈ¥½â¾ö£¬µ±Ò»¸öеÄÏîÄ¿À´µÄʱºò£¬×ÜÊÇϲ»¶È¥Éè¼ÆËü·ÖÎöËü£¬¿ÉºÜÄÑϵÚÒ»±ÊÈ¥±àдËü£¬²»ÖªµÀÊDz»ÊÇÀÏÁË£¬ÏëÁ˼¸ÌìÁËÕæ²»ÖªµÀÊDz»Êǵ½ÁËתÐÍʱÆÚÁË¡£ ......
¿ìÅÅ£º¿ìËÙÅÅÐò£¬ÄѶȲ»ÊÇÌ«´ó£¬µ«ÊÇÊÇÎÒ¾³£°ÑÍæµÄС´úÂëÖ®Ò»£¬ÒýÓÿìÅÅ´úÂ봴ʼÈ˵ÄÒ»¾ä»°“Òª²»ÊǼòÁ·ÓÖÃ÷ÏÔûÓдíÎó£¬Òª²»ÊǸ´ÔÓûÓÐÃ÷ÏԵĴíÎó”
ÆðÒò£º
Ö÷ÒªÊÇǰһÕó¿´ÁõÈê¼ÑµÄ¡¶Ëã·¨ÒÕÊõÓëÐÅϢѧ¾ºÈü¡·P73Ò³£¬ÅöÇÉÎÒÓÖÇ×ÊÖдÁËÒ»±éÄÇÊéÉϵIJâÊÔÁËһϣ¬·¢ÏÖ¾¹È»ÊÇ´íÎóµÄ£¬È»ºóÎÒÓÖ²âÊÔÁËÒ»ÏÂÎÒÒÔÇ ......
Java 7ÒѾÍê³ÉµÄÆß´óй¦ÄÜÔ¤ÀÀzz
2009-12-12 09:15
×î½üµÄDevoxx´ó»áÉÏ£¬Java 7½«°üº¬±Õ°üµÄÏûÏ¢ÁîºÜ¶àÈ˸е½Õñ·Ü——Õ⽫×öΪһ¸ö¶ÀÁ¢µÄJSR±»ÊµÏÖ¡£ÔÚÖÚ¶àJava 7еÄÓïÑÔÌØÐÔÖУ¬ÓÐһЩÏÖÔÚÒѾÍê³ÉÁË¡£Devoxx´ó»áµÄһλ²Î»áÕßÔÚ²©¿ÍÖб¨¸æÁËÏÂÃæÕâЩJava 7ÒѾÍê³ÉµÄ7´óй¦ÄÜ£º
1£©¶Ô¼¯ºÏÀàµÄÓïÑÔÖ§³Ö£»
......