JavaỊ̈߳ºÐÂÌØÕ÷ ÕÏ°Æ÷
JavaỊ̈߳ºÐÂÌØÕ÷-ÕÏ°Æ÷
Java5ÖУ¬Ìí¼ÓÁËÕÏ°Æ÷À࣬ΪÁËÊÊÓ¦Ò»ÖÖеÄÉè¼ÆÐèÇ󣬱ÈÈçÒ»¸ö´óÐ͵ÄÈÎÎñ£¬³£³£ÐèÒª·ÖÅäºÃ¶à×ÓÈÎÎñÈ¥Ö´ÐУ¬Ö»Óе±ËùÓÐ×ÓÈÎÎñ¶¼Ö´ÐÐÍê³Éʱºò£¬²ÅÄÜÖ´ÐÐÖ÷ÈÎÎñ£¬Õâʱºò£¬¾Í¿ÉÒÔÑ¡ÔñÕÏ°Æ÷ÁË¡£
ÕÏ°Æ÷ÊǶàÏ̲߳¢·¢¿ØÖƵÄÒ»ÖÖÊֶΣ¬Ó÷¨ºÜ¼òµ¥¡£ÏÂÃæ¸ø¸öÀý×Ó£º
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
/**
* JavaỊ̈߳ºÐÂÌØÕ÷-ÕÏ°Æ÷
*
* @author leizhimin 2009-11-6 10:50:10
*/
public class Test {
public static void main(String[] args) {
//´´½¨ÕÏ°Æ÷£¬²¢ÉèÖÃMainTaskΪËùÓж¨ÊýÁ¿µÄÏ̶߳¼´ïµ½ÕÏ°µãʱºòËùÒªÖ´ÐеÄÈÎÎñ(Runnable)
CyclicBarrier cb = new CyclicBarrier(7, new MainTask());
new SubTask("A", cb).start();
new SubTask("B", cb).start();
new SubTask("C", cb).start();
new SubTask("D", cb).start();
new SubTask("E", cb).start();
new SubTask("F", cb).start();
new SubTask("G", cb).start();
}
}
/**
* Ö÷ÈÎÎñ
*/
class MainTask implements Runnable {
public void r
Ïà¹ØÎĵµ£º
JavaỊ̈߳ºÏ̵߳Ľ»»¥
SCJP5ѧϰ±Ê¼Ç
Ï߳̽»»¥ÊDZȽϸ´ÔÓµÄÎÊÌ⣬SCJPÒªÇ󲻺ܻù´¡£º¸ø¶¨Ò»¸ö³¡¾°£¬±àд´úÂëÀ´Ç¡µ±Ê¹Óõȴý¡¢Í¨ÖªºÍ֪ͨËùÓÐÏ̡߳£
Ò»¡¢Ï߳̽»»¥µÄ»ù´¡ÖªÊ¶
SCJPËùÒªÇóµÄÏ߳̽»»¥ÖªÊ¶µãÐèÒª´Ójava.lang.ObjectµÄÀàµÄÈý¸ö·½·¨À´Ñ§Ï°£º
void notify()
......
JavaỊ̈߳ºÏ̵߳ĵ÷¶È-Èò½
Ï̵߳ÄÈò½º¬Òå¾ÍÊÇʹµ±Ç°ÔËÐÐ×ÅÏß³ÌÈóöCPU×ÊÔ´£¬µ«ÊÇÈ»¸ø˲»ÖªµÀ£¬½ö½öÊÇÈóö£¬Ïß³Ì״̬»Øµ½¿ÉÔËÐÐ״̬¡£
Ï̵߳ÄÈò½Ê¹ÓÃThread.yield()·½·¨£¬yield() Ϊ¾²Ì¬·½·¨£¬¹¦ÄÜÊÇÔÝÍ£µ±Ç°ÕýÔÚÖ´ÐеÄÏ̶߳ÔÏ󣬲¢Ö´ÐÐÆäËûÏ̡߳£
/**
* JavaỊ̈߳ºÏ̵߳ĵ÷¶È-Èò½
*
......
JavaỊ̈߳º²¢·¢Ð×÷-ËÀËø
Ï̷߳¢ÉúËÀËø¿ÉÄÜÐÔºÜС£¬¼´Ê¹¿´ËÆ¿ÉÄÜ·¢ÉúËÀËøµÄ´úÂ룬ÔÚÔËÐÐʱ·¢ÉúËÀËøµÄ¿ÉÄÜÐÔÒ²ÊÇС֮ÓÖС¡£
·¢ÉúËÀËøµÄÔÒòÒ»°ãÊÇÁ½¸ö¶ÔÏóµÄËøÏ໥µÈ´ýÔì³ÉµÄ¡£
ÔÚ¡¶JavaỊ̈߳ºÏ̵߳Äͬ²½ÓëËø¡·Ò»ÎÄÖУ¬¼òÊöËÀËøµÄ¸ÅÄîÓë¼òµ¥Àý×Ó£¬µ«ÊÇËù¸øµÄÀý×ÓÊDz»ÍêÕûµÄ£¬ÕâÀï¸ø³öÒ»¸öÍêÕûµÄÀ ......
ÉèÖÃ×¢ÊÍÄ£°åµÄÈë¿Ú£º Window->Preference->Java->Code Style->Code Template È»ºóÕ¹¿ªComments½Úµã¾ÍÊÇËùÓÐÐèÉèÖÃ×¢Ê͵ÄÔªËØÀ²¡£ÏÖ¾Íÿһ¸öÔªËØÖðÒ»½éÉÜ£º
Îļþ(Files)×¢ÊͱêÇ©£º
/**
* @Title: ${file_name}
* @Package ${package_name}
* @Description: ${todo}(ÓÃÒ»¾ä»°ÃèÊö¸ÃÎļ ......
JavaỊ̈߳ºÐÂÌØÕ÷-Ëø£¨Ï£©
ÔÚÉÏÎÄÖÐÌáµ½ÁËLock½Ó¿ÚÒÔ¼°¶ÔÏó£¬Ê¹ÓÃËü£¬ºÜÓÅÑŵĿØÖÆÁ˾ºÕù×ÊÔ´µÄ°²È«·ÃÎÊ£¬µ«ÊÇÕâÖÖËø²»Çø·Ö¶Áд£¬³ÆÕâÖÖËøΪÆÕͨËø¡£ÎªÁËÌá¸ßÐÔÄÜ£¬JavaÌṩÁ˶ÁдËø£¬ÔÚ¶ÁµÄµØ·½Ê¹ÓöÁËø£¬ÔÚдµÄµØ·½Ê¹ÓÃдËø£¬Áé»î¿ØÖÆ£¬ÔÚÒ»¶¨³Ì¶ÈÉÏÌá¸ßÁ˳ÌÐòµÄÖ´ÐÐЧÂÊ¡£
JavaÖжÁдËøÓиö½Ó¿Újava ......