黑马程序员技术交流社区
标题:
我自己写的7K面试题-银行模拟系统
[打印本页]
作者:
a283398689
时间:
2013-10-10 16:43
标题:
我自己写的7K面试题-银行模拟系统
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();
}
}
}
}
}
});
}
}
作者:
To
时间:
2013-10-10 17:52
不错~
作者:
a283398689
时间:
2013-10-10 20:02
自己练习 没发完代码~呵呵
作者:
李红亮
时间:
2013-10-16 10:08
好东西,有空我也学习这个
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2