黑马程序员-银行业务调度系统(自己写的)目前还有异常,不知道怎么处理?,银行业务调度系统
分享于 点击 10872 次 点评:53
黑马程序员-银行业务调度系统(自己写的)目前还有异常,不知道怎么处理?,银行业务调度系统
----------- android培训、java培训、java学习型技术博客、期待与您交流! ------------
public class Bank
{
public static void main(String[] args)
{
new Thread(new Number(1000)).start();//开启调用随机生成人员的线程
for(int i = 1 ;i<=10;i++)//开启10个窗口的线程
{
new Thread(new Monitor(i)).start();
}
}
}
class Monitor implements Runnable
{
public int y1;
public Monitor(int y1)
{
this.y1=y1;
}
public synchronized void sop()
{
if (Number.al1.size() > 0)
{
Number.al1.remove(0);//移除集合的第一个元素,表示处理好一个客户
System.out.println("第" + y1 + "窗口处理了一个普通客户");
try
{
Thread.sleep((new Random().nextInt(10)+1)*100);//处理一个客户用的时间随机取值
} catch (Exception e)
{
e.printStackTrace();
}
}
}
public void run()
{
while (true)
{
if (y1 >= 1 && y1 <= 6)
{
sop();
} else if (y1 == 7)
{
if (Number.al2.size() > 0)
{
Number.al2.remove(0);
System.out.println("第" + y1 + "窗口处理了一个VIP客户");
try
{
Thread.sleep((new Random().nextInt(10)+1)*100);
//处理一个客户用的时间随机取值
} catch (Exception e)
{
e.printStackTrace();
}
} else
{
sop();
}
} else
{
if (Number.al3.size() > 0)
{
Number.al3.remove(0);
System.out.println("第" + y1 + "窗口处理了一个快速客户");
try
{
Thread.sleep((new Random().nextInt(10)+1)*100);
//处理一个客户用的时间随机取值
} catch (Exception e)
{
e.printStackTrace();
}
} else
{
sop();
}
}
try
{
Thread.sleep((new Random().nextInt(10)+1)*100);
} catch (Exception e)
{
e.printStackTrace();
}
}
}
}
class Number implements Runnable
{
public int x;
public int o1;
public int o2=1;
public static int uuu=1;
public static ArrayList<String> al1,al2,al3;
public Number(int o1)//构造函数用于生成3个集合保存3种客户
{
this.o1=o1;
al1 = new ArrayList<String>();
al2 = new ArrayList<String>();
al3 = new ArrayList<String>();
}
public void run()
{
Randomgeneration();
}
public void Randomgeneration()
{
while(o2<=o1)
{
x = (int) (Math.random() * 10 + 1);//随机生成1-10用于判断来的人员是什么客户
Judge(x);
try
{
Thread.sleep((new Random().nextInt(10)+1)*100);
//这个时间要注意下,随机生成人员来的时间
} catch (Exception e)
{
e.printStackTrace();
}
o2++;//人员截至条件
}
}
public void Judge(int y)
{
if(y>=1&&y<=6)
{
al1.add("people");
System.out.println("第"+uuu+++"号来了一个普通客户");
//在普通客户的数组进行添加1个人员
}else if(y==7)
{
al2.add("people");
System.out.println("第"+uuu+++"号来了一个VIP客户");
//在VIP客户的数组进行添加1个人员
}else
{
al3.add("people");
System.out.println("第"+uuu+++"号来了一个快速客户");
//在快速客户的数组进行添加1个人员
}
}
}
----------------------- android培训、java培训、java学习型技术博客、期待与您交流! ----------------------
详情请查看:http://edu.csdn.net/heima
相关文章
- 暂无相关文章
用户点评