请哪位高手详细说一下到底线程是用来做什么的啊?
我刚刚学完了线程一章,可是我不太明白要怎么样才能实现线程的控制和多线程并行。我们老师还要求我们用线程的知识写一个订票系统的程序 ,可是我觉得这个程序根本用不到线程。请高手给我一点编这个程序的思路,不盛感激!!

解决方案 »

  1.   

    public class Test implements Runnable
    {

    int lens = 0;
    public Test(int len)
    {
    this.lens = len;
    }
    public void run()
    {

    while(lens>0)
    {
     System.out.println(Thread.currentThread().getName()+ lens-- +"已定出!");
     try{Thread.sleep(100);}catch(Exception e){}
        }
        
        System.out.println("票已售完!");
        
     }

    public static void main(String args[])
    {
    Test test = new Test(100);
    Thread t1 = new Thread(test,"1号售票处:");
    Thread t2 = new Thread(test,"2号售票处:");
    Thread t3 = new Thread(test,"3号售票处:");
    t1.start();
    t2.start();
    t3.start();
    }
    }
    参考下  三个窗口同时售100张票的情况