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

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

JavaỊ̈߳º²¢·¢Ð­×÷-Éú²úÕßÏû·ÑÕßÄ£ÐÍ
¶ÔÓÚ¶àÏ̳߳ÌÐòÀ´Ëµ£¬²»¹ÜÈκαà³ÌÓïÑÔ£¬Éú²úÕߺÍÏû·ÑÕßÄ£ÐͶ¼ÊÇ×î¾­µäµÄ¡£¾ÍÏñѧϰÿһÃűà³ÌÓïÑÔÒ»Ñù£¬Hello World£¡¶¼ÊÇ×î¾­µäµÄÀý×Ó¡£
ʵ¼ÊÉÏ£¬×¼È·ËµÓ¦¸ÃÊÇ¡°Éú²úÕß-Ïû·ÑÕß-²Ö´¢¡±Ä£ÐÍ£¬À뿪Á˲ִ¢£¬Éú²úÕßÏû·ÑÕßÄ£Ð;ÍÏÔµÃûÓÐ˵·þÁ¦ÁË¡£
¶ÔÓÚ´ËÄ£ÐÍ£¬Ó¦¸ÃÃ÷ȷһϼ¸µã£º
1¡¢Éú²úÕß½ö½öÔÚ²Ö´¢Î´ÂúʱºòÉú²ú£¬²ÖÂúÔòÍ£Ö¹Éú²ú¡£
2¡¢Ïû·ÑÕß½ö½öÔÚ²Ö´¢ÓвúƷʱºò²ÅÄÜÏû·Ñ£¬²Ö¿ÕÔòµÈ´ý¡£
3¡¢µ±Ïû·ÑÕß·¢ÏÖ²Ö´¢Ã»²úÆ·¿ÉÏû·Ñʱºò»á֪ͨÉú²úÕßÉú²ú¡£
4¡¢Éú²úÕßÔÚÉú²ú³ö¿ÉÏû·Ñ²úƷʱºò£¬Ó¦¸Ã֪ͨµÈ´ýµÄÏû·ÑÕßÈ¥Ïû·Ñ¡£
´ËÄ£Ðͽ«Òª½áºÏjava.lang.ObjectµÄwaitÓënotify¡¢notifyAll·½·¨À´ÊµÏÖÒÔÉϵÄÐèÇó¡£ÕâÊǷdz£ÖØÒªµÄ¡£
Java´úÂë
public class Test {
public static void main(String[] args) {
Godown godown = new Godown(30);
Consumer c1 = new Consumer(50, godown);
Consumer c2 = new Consumer(20, godown);
Consumer c3 = new Consumer(30, godown);
Producer p1 = new Producer(10, godown);
Producer p2 = new Producer(10, godown);
Producer p3 = new Producer(10, godown);
Producer p4 = new Producer(10, godown);
Producer p5 = new Producer(10, godown);
Producer p6 = new Producer(10, godown);
Producer p7 = new Producer(80, godown);

c1.start();
c2.start();
c3.start();
p1.start();
p2.start();
p3.start();
p4.start();
p5.start();
p6.start();
p7.start();
}
}
public class Test {
public static void main(String[] args) {
Godown godown = new Godown(30);
Consumer c1 = new Consumer(50, godown);
Consumer c2 = new Consumer(20, godown);
Consumer c3 =


Ïà¹ØÎĵµ£º

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

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

JavaỊ̈߳ºÐÂÌØÕ÷ Ëø£¨ÉÏ£©

JavaỊ̈߳ºÐÂÌØÕ÷-Ëø£¨ÉÏ£©
 
ÔÚJava5ÖУ¬×¨ÃÅÌṩÁËËø¶ÔÏó£¬ÀûÓÃËø¿ÉÒÔ·½±ãµÄʵÏÖ×ÊÔ´µÄ·âËø£¬ÓÃÀ´¿ØÖƶԾºÕù×ÊÔ´²¢·¢·ÃÎʵĿØÖÆ£¬ÕâЩÄÚÈÝÖ÷Òª¼¯ÖÐÔÚjava.util.concurrent.locks °üÏÂÃ棬ÀïÃæÓÐÈý¸öÖØÒªµÄ½Ó¿ÚCondition¡¢Lock¡¢ReadWriteLock¡£
 
Condition
Condition ½« Object ¼àÊÓÆ÷·½·¨£¨wait¡¢notify ......

JavaỊ̈߳ºÐÂÌØÕ÷ Ëø£¨Ï£©

JavaỊ̈߳ºÐÂÌØÕ÷-Ëø£¨Ï£©
 
ÔÚÉÏÎÄÖÐÌáµ½ÁËLock½Ó¿ÚÒÔ¼°¶ÔÏó£¬Ê¹ÓÃËü£¬ºÜÓÅÑŵĿØÖÆÁ˾ºÕù×ÊÔ´µÄ°²È«·ÃÎÊ£¬µ«ÊÇÕâÖÖËø²»Çø·Ö¶Áд£¬³ÆÕâÖÖËøΪÆÕͨËø¡£ÎªÁËÌá¸ßÐÔÄÜ£¬JavaÌṩÁ˶ÁдËø£¬ÔÚ¶ÁµÄµØ·½Ê¹ÓöÁËø£¬ÔÚдµÄµØ·½Ê¹ÓÃдËø£¬Áé»î¿ØÖÆ£¬ÔÚÒ»¶¨³Ì¶ÈÉÏÌá¸ßÁ˳ÌÐòµÄÖ´ÐÐЧÂÊ¡£
 
JavaÖжÁдËøÓиö½Ó¿Újava ......

JavaỊ̈߳ºÐÂÌØÕ÷ Ô­×ÓÁ¿

JavaỊ̈߳ºÐÂÌØÕ÷-Ô­×ÓÁ¿
 
ËùνµÄÔ­×ÓÁ¿¼´²Ù×÷±äÁ¿µÄ²Ù×÷ÊÇ“Ô­×ӵĔ£¬¸Ã²Ù×÷²»¿ÉÔÙ·Ö£¬Òò´ËÊÇḬ̈߳²È«µÄ¡£
 
ΪºÎҪʹÓÃÔ­×Ó±äÁ¿ÄØ£¬Ô­ÒòÊǶà¸öÏ̶߳Ե¥¸ö±äÁ¿²Ù×÷Ò²»áÒýÆðһЩÎÊÌâ¡£ÔÚJava5֮ǰ£¬¿ÉÒÔͨ¹ývolatile¡¢synchronized¹Ø¼ü×ÖÀ´½â¾ö²¢·¢·ÃÎʵݲȫÎÊÌ⣬µ«ÕâÑùÌ«Âé·³¡£
Java5Ö®ºó£¬× ......

JavaÅÅÐò·½·¨´óÈ«

°æȨÉùÃ÷£º×ªÔØʱÇëÒÔ³¬Á´½ÓÐÎʽ±êÃ÷ÎÄÕÂԭʼ³ö´¦ºÍ×÷ÕßÐÅÏ¢¼°±¾ÉùÃ÷
http://as112255.blogbus.com/logs/38662785.html
package com.softeem.jbs.lesson4;
 
import java.util.Random;
 
/**
 * ÅÅÐò²âÊÔÀà
 *
 * ÅÅÐòËã·¨µÄ·ÖÀàÈçÏ£º
 * 1.²åÈëÅÅÐò£¨Ö±½Ó²åÈëÅÅÐò¡¢ÕÛ°ë²åÈëÅÅÐ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ