java ¶àÏß³ÌÖ® wait(),notify(),notifyAll()
http://www.cnblogs.com/anran_guojianjun/archive/2009/04/14/1435278.html
wait(),notify(),notifyAll()²»ÊôÓÚThreadÀà,¶øÊÇÊôÓÚObject»ù´¡Àà,Ò²¾ÍÊÇ˵ÿ¸ö¶ÔÏñ¶¼ÓÐ
wait(),notify(),notifyAll()
µÄ¹¦ÄÜ.ÒòΪ¶¼¸ö¶ÔÏñ¶¼ÓÐËø,ËøÊÇÿ¸ö¶ÔÏñµÄ»ù´¡,µ±È»²Ù×÷ËøµÄ·½·¨Ò²ÊÇ×î»ù´¡ÁË.
ÏÈ¿´java docÔõô˵:
waitµ¼Öµ±Ç°µÄÏ̵߳ȴý£¬Ö±µ½ÆäËûÏ̵߳÷Óô˶ÔÏóµÄ notify() ·½·¨»ò notifyAll()
·½·¨¡£µ±Ç°µÄÏ̱߳ØÐëÓµÓд˶ÔÏó¼àÊÓÆ÷¡£¸ÃÏ̷߳¢²¼¶Ô´Ë¼àÊÓÆ÷µÄËùÓÐȨ²¢µÈ´ý£¬Ö±µ½ÆäËûÏß³Ìͨ¹ýµ÷Óà notify ·½·¨£¬»ò notifyAll
·½·¨Í¨ÖªÔڴ˶ÔÏóµÄ¼àÊÓÆ÷ÉϵȴýµÄÏß³ÌÐÑÀ´¡£È»ºó¸ÃÏ߳̽«µÈµ½ÖØлñµÃ¶Ô¼àÊÓÆ÷µÄËùÓÐȨºó²ÅÄܼÌÐøÖ´ÐÐ.
notify»½ÐÑÔڴ˶ÔÏó¼àÊÓÆ÷ÉϵȴýµÄµ¥¸öÏ̡߳£Èç¹ûËùÓÐÏ̶߳¼Ôڴ˶ÔÏóÉϵȴý£¬Ôò»áÑ¡Ôñ»½ÐÑÆäÖÐÒ»¸öÏ̡߳£Ö±µ½µ±Ç°µÄÏ̷߳ÅÆú´Ë¶ÔÏóÉϵÄËø
¶¨£¬²ÅÄܼÌÐøÖ´Ðб»»½ÐѵÄÏ̡߳£´Ë·½·¨Ö»Ó¦ÓÉ×÷Ϊ´Ë¶ÔÏó¼àÊÓÆ÷µÄËùÓÐÕßµÄÏß³ÌÀ´µ÷ÓÃ.
"µ±Ç°µÄÏ̱߳ØÐëÓµÓд˶ÔÏó¼àÊÓÆ÷"Óë"´Ë·½·¨Ö»Ó¦ÓÉ×÷Ϊ´Ë¶ÔÏó¼àÊÓÆ÷µÄËùÓÐÕßµÄÏß³ÌÀ´µ÷ÓÃ"˵Ã÷wait·½·¨Óënotify·½·¨±ØÐëÔÚͬ²½¿éÄÚÖ´
ÐÐ,¼´synchronized(objÖ®ÄÚ).
µ÷ÓöÔÏñwait·½·¨ºó,µ±Ç°Ïß³ÌÊͷŶÔÏñËø,½øÈëµÈ´ý״̬.Ö±µ½ÆäËûÏß³Ì(Ò²Ö»ÄÜÊÇÆäËûÏß³Ì)ͨ¹ýnotify ·½·¨£¬»ò
notifyAll.¸ÃÏß³ÌÖØлñµÃ¶ÔÏñËø.
¼ÌÐøÖ´ÐÐ,¼ÇµÃÏ̱߳ØÐëÖØлñµÃ¶ÔÏñËø²ÅÄܼÌÐøÖ´ÐÐ.ÒòΪsynchronized´úÂë¿éÄÚûÓÐËøÊÇ´ç²½²»ÄÜ×ßµÄ.¿´Ò»¸öºÜ¾µäµÄÀý×Ó:
package ProductAndConsume;
import java.util.List;
public class Consume implements Runnable{
private List container = null;
private int count;
public Consume(List lst){
this.container = lst;
}
public void run() {
while(true){
synchronized (container) {
if(container.size()== 0){
try {
container.wait();//·ÅÆúËø
} catch (InterruptedException e) {
e.printStackTrace();
}
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
container.remove(0);
container.notify();
System.out.println("ÎÒ³ÔÁË"+(++count)+"¸ö");
}
}
}
}
package ProductAndC
Ïà¹ØÎĵµ£º
µ±ÄãÔÚÄã×Ô¼ºµÄµçÄÔÉÏ×°µÄ¶«Î÷±È½Ï¶àµÄʱºò£¬¶øÇÒÖ´ÐгÌÐòÓкÜÂÒ£¬ÈÃÄãÒ²ºÜ²»ºÃÕÒ£¬ÏÂÃæÕâ¸öÊÇÎÒÓÃjavaдµÄÒ»¶ÎС³ÌÐò£¬Ö±½ÓÔÚÄãµÄÔËÐд°¿ÚÊäÈë java open ??¾Í¿ÉÒÔ´ò¿ªÄã×Ô¼ºµÄÏëÒªµÄ»·¾³»òÕß¹¤¾ßÁË
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class open {
publi ......
Part 2£ºWeb²ã¹¦ÄÜÔöÇ¿
ÔÚJavaEE6ÖУ¬Web²ãÓÐÏÔÖøµÄ¹¦ÄÜÔöÇ¿¡£ÈçÉÏÎÄËùÊö£¬JavaaEE6ƽ̨µÄÄ¿±êÖ®Ò»¾ÍÊÇÔöÇ¿Æä¿ÉÀ©Õ¹ÐÔ£¬¶øÓë¿ÉÀ©Õ¹ÐÔÏà¹ØµÄÁ½¸ö¹Ø¼ü¼¼Êõ±ãÊÇ£ºWebƬ¶Ï£¨web fragments£©¡¢¹²Ïí¿ò¼Ü¿É²å°ÎÄÜÁ¦£¨shared framework pluggability£©£¬¶øÕâÁ½¸öÐÂÌØÐÔÊÇÓÉservlet3.0¼¼Êõ×é¼þÌṩµÄ¡£Servlet 3.0, JSR 315
ÊÇserv ......
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
im ......
7. ÓÃJavaXPCOMÀ´×Ô¶¯ä¯ÀÀÍøÒ³
ÔÚÕâÒ»½ÚÀïÎÒÃǽ«½â¾öһЩ×Ô¶¯ä¯ÀÀÍøÒ³ÖеÄһЩÎÊÌ⣬³¢ÊÔ°ÑÒ»ÏÂͨÓõÄÈÎÎñ³éÏó³ÉÈËÀà¿É¶ÁµÄ·½·¨£¬Òò´ËÄã¿ÉÒÔÇáÒ×µÄÔĶÁ
´úÂë²¢ÖªµÀËüµÄ¹¦ÄÜ¡£ÎÒÃǽ«¹¹½¨Ò»¸öWeb BrowserÀ´¼ÓÔØÍøÒ³£¬µã»÷°´Å¥»òÕß³¬Á´½Ó£¬Ê¹ÓÃXPathÀ´³éÈ¡Ò»ÏÂÓÐÓõÄÐÅÏ¢¡£ÔÚÿһ¸ö
С½ÚÀïÃ棬ÎÒÃǶ¼½«ÔÚÎÒÃǵ ......