🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: cn.bbs.comp.lang.java
1 messages
1 total messages Started by ��ɵ��� Tue, 24 Feb 2009 06:26
�����̵߳�����
#277
Author: ��ɵ���
Date: Tue, 24 Feb 2009 06:26
82 lines
2802 bytes
class ham                                       //��װ������ĺ�����Ϊ��������
{
    static Object box=new Object();
    static int totalmaterial=10;
    static int sales=0;
    static int production=5;
}
class hmaker extends Thread                      //��ʦ�߳���
{
    public void make()
    {
        synchronized(ham.box)
        {
            (ham.production)++;
            try
            {
                ham.box.notify();
            }
            catch(Exception e){}
        } 
    }
    public void run()
    {
        while(ham.production<ham.totalmaterial)
        {      
            if(ham.production>0) 
            {
                System.out.println("��ʦ"+getName()+":"+"��������(�ܹ�"+(ham.production-ham.sales)+"��)");
            } 
            try 
            { 
                sleep(3000);
            } 
            catch(Exception e){}
            make(); 
        } 
     } 
}
class hassistant extends Thread 
{
    public void sell()
    {
        if(ham.production==0)
        {
            System.out.println("ӪҵԱ���˿������ǣ�����΢��һ��,����û��!!");
        }
        try 
        { 
            ham.box.wait();
        } 
        catch(Exception e){} 
        ham.sales++; 
        System.out.println("ӪҵԱ���˿ͺã����������ˣ����ܹ�����"+ham.sales+"����"); 
    }
    public void run()
    { 
        while(ham.sales<ham.production)
        { 
            try 
            { 
                sleep(1000); 
            } 
            catch(Exception e){} 
            sell(); 
        } 
    } 
} 
public class thread13 
{ 
    public static void main(String[] args) 
    { 
        hmaker maker=new hmaker(); 
        hassistant assistant=new hassistant(); 
        maker.setName("��"); 
        maker.start(); 
        assistant.start(); 
    }
}


--
�� ��Դ:�������ʵBBS http://bbs.tju.edu.cn [FROM: 211.81.57.181]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads