zoukankan      html  css  js  c++  java
  • 多线程模拟售票系统2

    package com.smbea.demo.thread;
    
    public class SaleTicket3 {
        private static int count = 20;	// 总票数
        
        private static synchronized boolean sell(String node){
            if(0 < count){
                count--;
                System.out.println("第 " + node + " 窗口售出第 " + (20 - count) + " 张票,还剩 " + count + " 张票");
                
                return true;
            }
            
            return false;
        }
        
        static class Window extends Thread{	// 售票窗口
            String node;	// 售票窗口编号
            
            public Window(String node){
                this.node = node;
            }
            
            public void run(){
                while(sell(node)){
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        
        public static void main(String[] args) {
            new Window("A").start();
            new Window("B").start();
            new Window("C").start();
        }
    }
    

      

  • 相关阅读:
    亚瑟阿伦36问
    Oracle动态SQL
    Oracle分页
    Oracle游标+动态SQL
    Oracle %type %rowtype
    Oracle游标
    Oracle存储过程和Java调用
    Oracle循环
    Oracle(if判断)
    Oracle视图
  • 原文地址:https://www.cnblogs.com/hapday/p/6263494.html
Copyright © 2011-2022 走看看