package com.itheima.bankDealSystem;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class DealWindows {
// private List user;
public DealWindows (final ArrayList<User> user){
ExecutorService nomalwindow = Executors.newSingleThreadExecutor();
ExecutorService nomalwindow1 = Executors.newSingleThreadExecutor();
ExecutorService nomalwindow2 = Executors.newSingleThreadExecutor();
ExecutorService nomalwindow3 = Executors.newSingleThreadExecutor();
ExecutorService fastwindow = Executors.newSingleThreadExecutor();
ExecutorService vipwindow = Executors.newSingleThreadExecutor();
nomalwindow.execute(new Runnable() {
@Override
public void run() {
while(user.size()==0){
try {
Thread.sleep(5000);
System.out.println("没有客户喝杯茶");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
while(user.size()>0){
//System.out.println(k);
for(int i=0; i<user.size()+5;i++ ){
long dealtime = (new Random().nextInt(10)+1)*1000;
User u = user.get(0);
if(u!=null&&u.getType()==UserType.NORMALUSER&&!u.isProcessing()){
try {
u.setProcessing(true);
System.out.println("1号普通窗口:"+"id为"+u.getId()+"真正进行业务处理,业务类型为"+u.getType());
Thread.sleep(dealtime);
System.out.println("id为"+u.getId()+"业务处理完成欢迎,下个一个客户来1号普通窗口");
user.remove(u);
while(user.size()==0){
try {
Thread.sleep(5000);
System.out.println("没有客户喝杯茶");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
});
nomalwindow1.execute(new Runnable() {
@Override
public void run() {
while(user.size()==0){
try {
Thread.sleep(7000);
System.out.println("没有客户喝杯茶");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
while(user.size()>0){
for(int i=0; i<user.size()+5;i++ ){
// long dealtime = (new Random().nextInt(10)+1)*1000;
User u = user.get(0);
if(u!=null&&u.getType()==UserType.NORMALUSER&&!u.isProcessing()){
try {
u.setProcessing(true);
System.out.println("2号普通窗口:"+"id为"+u.getId()+"真正进行业务处理,业务类型为"+u.getType());
Thread.sleep( (new Random().nextInt(8)+1)*1000);
System.out.println("id为"+u.getId()+"业务处理完成欢迎,下个一个客户来2号普通窗口");
user.remove(u);
while(user.size()==0){
try {
Thread.sleep(5000);
System.out.println("没有客户喝杯茶");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
});
nomalwindow2.execute(new Runnable() {
@Override
public void run() {
while(user.size()==0){
try {
Thread.sleep(15000);
System.out.println("没有客户喝杯茶");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
while(user.size()>0){
for(int i=0; i<user.size()+5;i++ ){
long dealtime = (new Random().nextInt(10)+1)*1000;
User u = user.get(0);
if(u!=null&&u.getType()==UserType.NORMALUSER&&!u.isProcessing()){
try {
u.setProcessing(true);
System.out.println("3号普通窗口:"+"id为"+u.getId()+"真正进行业务处理,业务类型为"+u.getType());
Thread.sleep(dealtime);
System.out.println("id为"+u.getId()+"业务处理完成欢迎,下个一个客户来3号普通窗口");
user.remove(u);
while(user.size()==0){
try {
Thread.sleep(5000);
System.out.println("没有客户喝杯茶");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
});
nomalwindow3.execute(new Runnable() {
//private boolean exist=false;
int count = 0;
@Override
public void run() {
while(user.size()==0){
try {
Thread.sleep(9000);
System.out.println("没有客户喝杯茶");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
while(user.size()>0){
for(int i=0; i<user.size()+5;i++ ){
long dealtime = (new Random().nextInt(10)+1)*1000;
User u = user.get(0);
if(u!=null&&u.getType()==UserType.NORMALUSER&&!u.isProcessing()){
try {
u.setProcessing(true);
System.out.println("4号普通窗口:"+"id为"+u.getId()+"真正进行业务处理,业务类型为"+u.getType());
Thread.sleep(dealtime);
System.out.println("id为"+u.getId()+"业务处理完成欢迎,下个一个客户来4号普通窗口");
user.remove(u);
while(user.size()==0){
try {
Thread.sleep(5000);
System.out.println("没有客户喝杯茶");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
});
fastwindow.execute(new Runnable() {
int count =0;
@Override
public void run() {
while(user.size()==0){
try {
Thread.sleep(12000);
System.out.println("没有客户喝杯茶");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
while(user.size()>0){
for(int i=0; i<user.size()+5;i++ ){
long dealtime = new Random().nextInt(2)*1000;
User u = user.get(0);
if(u!=null&&u.getType()==UserType.FASTUSER&&!u.isProcessing()){
try {
u.setProcessing(true);
System.out.println("快速窗口:"+"id为"+u.getId()+"真正进行业务处理,业务类型为"+u.getType());
Thread.sleep(dealtime);
System.out.println("id为"+u.getId()+"业务处理完成欢迎,下个一个客户来1号快速处理窗口");
user.remove(u);
while(user.size()==0){
try {
Thread.sleep(5000);
System.out.println("没有客户喝杯茶");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
});
vipwindow.execute(new Runnable() {
int count = 0;
@Override
public void run() {
while(user.size()==0){
try {
Thread.sleep(5000);
System.out.println("没有客户喝杯茶");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
while(user.size()>0){
for(int i=0; i<user.size()+5;i++ ){
long dealtime = new Random().nextInt(2)*1000;
User u = user.get(0);
if(u!=null&&u.getType()==UserType.VIPUSER&&!u.isProcessing()){
try {
u.setProcessing(true);
System.out.println("VIP窗口:"+"id为"+u.getId()+"真正进行业务处理,业务类型为"+u.getType());
Thread.sleep(dealtime);
System.out.println("id为"+u.getId()+"业务处理完成欢迎,下个一个客户来1号VIP");
user.remove(u);
while(user.size()==0){
try {
Thread.sleep(5000);
System.out.println("没有客户喝杯茶");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
});
}
}
|
|