本帖最后由 masai158 于 2014-8-20 17:25 编辑
- class Ticket
- {
- private String name;
- private int countTicket = 0;
-
- public Ticket(String name)
- {
- this.name = name;
-
- final ExecutorService threadPool = Executors.newFixedThreadPool(1);
- threadPool.execute(new Runnable()
- {
- public void run()
- {
- System.out.println(Ticket.this.name + ":开始卖票了" );
-
- while(TicketSealCenter.newInstance.getTicketNumber()) //去查询售票中心 是否还有票
- {
- System.out.println(Ticket.this.name + ":卖出了他的第:" + (++countTicket) + "张票,还剩" + TicketSealCenter.newInstance.sellTicketNnumber() + "张");
- }
- System.out.println(Ticket.this.name + ":没票了,本次他共计卖出了" + countTicket + "张票");
-
-
- /**如使用完线程池以后,必须要记住 要关闭,不然他可是会一直,知道你的程序结束
- * */
- threadPool.shutdown();
- }
- });
- }
- }
复制代码
bu 知道能不能帮你
- public enum Lamp
- {
- RED(10){
- public Lamp nextLamp()
- {
- return GREEN_3;
- }
- },
- GREEN_3(30){
- public Lamp nextLamp()
- {
- return RED;
- }
- },
- GREEN_2(20)
- {
- public Lamp nextLamp()
- {
- return RED;
- }
-
- },
- GREEN_1(10)
- {
- public Lamp nextLamp()
- {
- return RED;
- }
- };
-
-
- protected int time;
-
- private Lamp(int time)
- {
- this.time = time;
- }
-
- public abstract Lamp nextLamp();
- }
复制代码
2个。看对你有帮助不
|