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

Java Ï̱߳à³ÌÖеÄͬ²½¡¢Öظ´¡¢¶¨Ê±

£¨Ò»£©Ïß³Ìͬ²½
ʵÏÖÉú²úÕßÏû·ÑÕßÎÊÌâÀ´ËµÃ÷Ïß³ÌÎÊÌâ,¾ÙÀýÈçÏÂËùʾ:
/**
* Éú²úÕßÏû·ÑÕßÎÊÌâ
*/
public class ProducerConsumer {

/**
* Ö÷·½·¨
*/
public static void main(String[] args) {
ProductBox pb = new ProductBox();
Producer p = new Producer(pb);
Consumer c = new Consumer(pb);

//¸ù¾ÝÏû·ÑÕß¡¢Éú²úÕßÉú³ÉÏß³Ì
Thread pThread = new Thread(p);
Thread cThread = new Thread(c);
pThread.setPriority(Thread.MAX_PRIORITY);

pThread.start();
cThread.start();
}

}

/**
* ²úÆ·¶ÔÏó
* @author johsnton678
*/
class Product {
int id;

public Product(int id) {
super();
this.id = id;
}

public String toString(){
return "Product:" + id;
}
}

/**
* ²úÆ·ºÐ¶ÔÏó
* @author johnston678
*/
class ProductBox {

Product[] productbox = new Product[6];
int index = 0;
public ProductBox() {
super();
}

//´æÈë·½·¨£¬½«²úÆ·´æÈë²úÆ·ºÐ
public synchronized void push(Product p) {
//ÅжϲúÆ·ÊÇ·ñ³¬³ö²úÆ·ºÐµÄ×î´óÈÝÁ¿£¬Èç¹û³¬³öÖÐÔòµÈ´ý
while (index == productbox.length) {
try {
this.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
this.notify();
productbox[index] = p;
index ++;
}

//È¡³ö²Ù×÷
public synchronized Product pop() {
//Èç¹û²ú


Ïà¹ØÎĵµ£º

JavaÖм¯ºÏÈÝÆ÷ÀàListºÍSetµÄÓ÷¨

ListµÄÓ÷¨
List°üÀ¨List½Ó¿ÚÒÔ¼°List½Ó¿ÚµÄËùÓÐʵÏÖÀà¡£ÒòΪList½Ó¿ÚʵÏÖÁËCollection½Ó¿Ú£¬ËùÒÔList½Ó¿ÚÓµÓÐCollection½Ó¿ÚÌṩµÄËùÓг£Ó÷½·¨£¬ÓÖÒòΪListÊÇÁбíÀàÐÍ£¬ËùÒÔList½Ó¿Ú»¹ÌṩÁËһЩÊʺÏÓÚ×ÔÉíµÄ³£Ó÷½·¨£¬Èç±í1Ëùʾ¡£
±í1  List½Ó¿Ú¶¨ÒåµÄ³£Ó÷½·¨¼°¹¦ÄÜ
´Ó±í1¿ÉÒÔ¿´³ö£¬List½Ó¿ÚÌṩµÄÊʺÏÓÚ×ÔÉíµÄ ......

JAVAµÄ×Ö·û´®Æ´½ÓÓëÐÔÄÜ

Ô­ÌûµØÖ·:
http://coolshell.cn/?p=2235
----------------ÎÒÊÇ×ÏÔ·×îÃȵķָîÏßXD--------------
¸ÅÊö£º
±¾ÎÄÖ÷ÒªÑо¿µÄÊÇJAVAµÄ×Ö·û´®Æ´½ÓµÄÐÔÄÜ£¬Ô­ÎÄÖеIJâÊÔ´úÂëÔÚ¹¦ÄÜÉϲ¢²»µÈ¼Û£¬µ¼ÖÂconcatµÄ²â
ÊÔÒâÒå²»´ó¡£²»¹ýÔ­×÷ÕßÔÚÆÀÂÛÀ¸¸øÁËеÄconcat½á¹û£¬Èç¹ûÓÐÐËȤµÄͬѧ½¨Òé×Ô¼ºÐ޸ĴúÂë²âÊÔ¡£
Ô­Îijö´¦:http://ww ......

³õѧjava£¬Ò»Ð©¸ÅÄî

1. javaÓëƽ̨Î޹ء£Ô´´úÂëÓɱàÒëÆ÷±àÒëΪ×Ö½ÚÂ루JVM¿ÉÖ´ÐдúÂ룩£»½âÊÍÆ÷ÔËÐÐJVM×Ö½ÚÂ루·­ÒëΪ»úÆ÷Â룩¼´¿ÉµÃµ½Êä³ö½á¹û¡£
×Ö½ÚÂë¿ÉÔÚ¶à¸öƽ̨ÔËÐУ¬²»ÐèÒªÖØбàÒë¡£
c±àÒëÆ÷ÔÚ±àÒëʱÉú³ÉµÄ´úÂëÊÇÕë¶ÔÌض¨µÄÓ²¼þƽ̨²úÉúµÄ¡£
2. java¿ª·¢¹¤¾ßJDK¡£°²×°JDKʱ×Ô´øjre£¬¾ÍÊÇjavaÐéÄâ»ú¡£
jdkÊÇJava¿ª·¢¹¤¾ß°ü£¬°üº¬Á˸ ......

Java Native Interface ÈëÃÅʾÀý

¼øÓÚÍøÉÏËѵ½µÄ¶¼ÊÇ»ùÓÚjdk1.4»òÒÔÇ°°æ±¾£¬¶øÇÒ±¾µØ¿âÓõÄÊÇCÓïÑÔ¡£¶øÏÖÔÚÊÇ»ùÓÚC++£¬ËùÒÔ¸üмǼÈçÏ£º
µÚÒ»²½£º´´½¨JavaÔ´ÂëÎļþ
public class Hello{
        static{
                System.loa ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ