博客
关于我
java生成固定和的多个随机数、线程如何传值(构造方法)
阅读量:502 次
发布时间:2019-03-07

本文共 914 字,大约阅读时间需要 3 分钟。

实现3个卖票窗口,一共卖100张票的模拟卖票环节

package cn.code.day3_17Thread;import java.lang.Thread;import java.util.Random;public class TestThread {       public static void main(String[] args) {           //1.生成3个随机的售票数        Random r1 = new Random();        Random r2 = new Random();        int a = r1.nextInt(101);        int loss = 100 - a + 1;        int b = r2.nextInt(loss);        int c = 100-b-a;        //3.生成3个窗口        MyThread sell1 = new MyThread(a);        sell1.setName("窗口1");        MyThread sell2 = new MyThread(b);        sell2.setName("窗口2");        MyThread sell3 = new MyThread(c);        sell3.setName("窗口3");        //4.售票环节        sell1.start();        sell2.start();        sell3.start();    }}//2.设定三个售票窗口的线程,问题,如何将票数传递给线程?//通过构造函数传值class MyThread extends Thread{       private  int a;    public MyThread(int a)    {           this.a=a;    }    @Override    public void run() {           for (int i = 0; i 

转载地址:http://iqbcz.baihongyu.com/

你可能感兴趣的文章
neo4j图形数据库Java应用
查看>>
Neo4j图数据库_web页面关闭登录实现免登陆访问_常用的cypher语句_删除_查询_创建关系图谱---Neo4j图数据库工作笔记0013
查看>>
Neo4j图数据库的介绍_图数据库结构_节点_关系_属性_数据---Neo4j图数据库工作笔记0001
查看>>
Neo4j图数据库的数据模型_包括节点_属性_数据_关系---Neo4j图数据库工作笔记0002
查看>>
Neo4j安装部署及使用
查看>>
Neo4j电影关系图Cypher
查看>>
Neo4j的安装与使用
查看>>
Neo4j(1):图数据库Neo4j介绍
查看>>
Neo4j(2):环境搭建
查看>>
Neo4j(3):Neo4j Desktop安装
查看>>
Neo4j(4):Neo4j - CQL使用
查看>>
Neo图数据库与python交互
查看>>
NEO改进协议提案1(NEP-1)
查看>>
Neo私链
查看>>
NervanaGPU 项目使用教程
查看>>
Nerves 项目教程
查看>>
nessus快速安装使用指南(非常详细)零基础入门到精通,收藏这一篇就够了
查看>>
Nessus漏洞扫描教程之配置Nessus
查看>>
Nest.js 6.0.0 正式版发布,基于 TypeScript 的 Node.js 框架
查看>>
nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML.
查看>>