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 ......
BODY { color: #000000; font-size: 9pt; font-family: ËÎÌå }
TABLE { font-size: 9pt; font-family: ËÎÌå }
SimpleDateFormat sdfy = new SimpleDateFormat("HH:mm");
String tt =
"Tue Feb 09 10:43:00 CST 2010";
&n ......
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 ......
ÕâÆª½Ì³Ì¸üÐÂÓÚ2008ÄêÏÄÌ죬ÓÃÀ´¼¯³ÉSWTºÍXULRunnerÀ´ÔÚSWTÀïÏÔʾһ¸öä¯ÀÀÆ÷¡£ÒªÏë»ñµÃ¸ü¶àÐÅÏ¢£¬Çë²Î¿¼
http://www.eclipse.org/swt/faq.php#whatisbrowser
1£¬¼ò½é
ÕâÆª½Ì³ÌÓÐÁ½¸öÄ¿µÄ¡£Ê×ÏÈ£¬ÎÒÃÇÄÜѧµ½Ò»Ð©XPCOMµÄ¸ÅÄîºÍÔõôͨ¹ýJavaXPCOMÀ´ÔÚjavaÀïʹÓÃËü¡£Æä´Î£¬ÎÒÃÇѧµ½Ôõà ......