Java¶àÏß³Ì: Éú²úÕßÏû·ÑÕßÎÊÌâ(Ô´Âë)
ÓÐÈË·´Ó³¿´²»µ½Ô´Â룬·¢ÏÖÊÇCSDNµÄ´úÂë¿Ø¼þÓÐÎÊÌ⡣ϣÍûCSDNºÃºÃ¸Ä½øһϡ£
ÔÝʱÏÈÒÔÎı¾·½Ê½·¢²¼³öÀ´£¬¸ñʽ»á±äÑù¡£
import java.util.LinkedList;
public class ProducerConsumer
{
/**
* @param args
*/
public static void main(String[] args)
{
Queue queue = new Queue();
Producer producer1 = new Producer(queue, "producer1");
Producer producer2 = new Producer(queue, "producer2");
Consumer consumer1 = new Consumer(queue, "consumer1");
Consumer consumer2 = new Consumer(queue, "consumer2");
Consumer consumer3 = new Consumer(queue, "consumer3");
producer1.start();
producer2.start();
consumer1.start();
consumer2.start();
consumer3.start();
}
}
class Message
{
public static int sno = 0;
public int id = 0;
public String content = null;
public Message(String content)
{
synchronized(Message.class)
{
this.id = ++sno;
}
this.content = content;
}
public String toString()
{
return "id = " + id + ", content = " + content;
}
}
class Queue
{
private LinkedList queue = null;
private int capacity = 0;
public Queue(int capacity)
{
this.capacity = capacity;
queue = new LinkedList();
}
public Queue()
{
this(10);
}
public synchronized void put(Message product)
{
//wait until the consumer has consume a product
while(queue.size() >= capacity)
{
try
{
wait();
}
catch (InterruptedException e)
{
&
Ïà¹ØÎĵµ£º
×î½üÏîÄ¿½ø¶È±È½Ï»ºÂý£¬³õ²½Ñо¿ÁËÒ»ÏÂOracleµÄ´æ´¢¹ý³Ì£¬½«´úÂëÌù³öÀ´¡£
Ê×ÏÈÏÈÌù³öÀ´OracleµÄ·ÖÒ³·ÖÒ³´æ´¢¹ý³Ì´úÂë°É¡£
1.ÕâÊÇ°üµÄ´úÂë
create or replace package DB_Oper is
-- Author : LIUBING
-- Created : 2009-10-28 15:01:30
-- Purpose : ²âÊÔOracleµ ......
1. import java.util.*;
2.(A) public class Test
{ public static void main(String[] args)
{
//Éú³É [0-n) ¸ö²»Öظ´µÄËæ»úÊý st ÓÃÀ´±£´æ ......
ÎÊÌ⣺ÏÖÓÐn¸öÀÏÊóΧ³ÉһԲȦ£¬ÓÐһֻè´ÓÈÎÒâλÖÿªÊ¼³ÔÀÏÊó£¬Ã¿´Î¶¼¸ôÒ»¸öÀÏÊó³Ô£¬Çë¸ø³ö×îºóÒ»¸öÀÏÊóµÄ±àºÅ£¿ÌâÄ¿ÒªÇóÊÇÈθøÀÏÊóÊýn£¬Êä³öè×îºó³ÔµÄÀÏÊóµÄ±àºÅ¡£
ÎҵĽⷨ£º
1.¼òµ¥µÄ·½·¨¾ÍÊÇÄ£ÄâÕâ¸ö¹ý³Ì¡£Ê¹ÓÃÒ»¸öÊý×é´ú±íÀÏÊóÊÇ·ñ±»³Ôµô£¬Ñ»·±éÀú¡£
2.¸Ä½øһϵķ½·¨£¬ÆäʵÕâ¸öÎÊÌâ¾ÍÊÇÒ»¸öm=2µÄԼɪ·ò»·ÎÊÌâ¡£
......
3.Sun HotSpot
¡¡¡¡1.4.1 JVM¶Ñ´óСµÄµ÷Õû
¡¡¡¡Sun HotSpot 1.4.1ʹÓ÷ִúÊÕ¼¯Æ÷£¬Ëü°Ñ¶Ñ·ÖΪÈý¸öÖ÷ÒªµÄÓò£ºÐÂÓò¡¢¾ÉÓòÒÔ¼°ÓÀ¾ÃÓò¡£JvmÉú³ÉµÄËùÓÐжÔÏó·ÅÔÚÐÂÓòÖС£Ò»µ©¶ÔÏó¾ÀúÁËÒ»¶¨ÊýÁ¿µÄÀ¬»øÊÕ¼¯Ñ»·ºó£¬±ã»ñµÃʹÓÃÆÚ²¢½øÈë¾ÉÓò¡£ÔÚÓÀ¾ÃÓòÖÐjvmÔò´æ´¢classºÍmethod¶ÔÏó¡£¾ÍÅäÖöøÑÔ£¬ÓÀ¾ÃÓòÊÇÒ»¸ö¶ÀÁ¢Óò²¢ÇÒ²» ......