-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBank.java
executable file
·80 lines (60 loc) · 1.59 KB
/
Bank.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Bank.java
/*
Creates a bunch of accounts and uses threads
to post transactions to the accounts concurrently.
*/
import java.io.*;
import java.util.*;
public class Bank {
public static final int ACCOUNTS = 20; // number of accounts
/*
Reads transaction data (from/to/amt) from a file for processing.
(provided code)
*/
public void readFile(String file) {
try {
BufferedReader reader = new BufferedReader(new FileReader(file));
// Use stream tokenizer to get successive words from file
StreamTokenizer tokenizer = new StreamTokenizer(reader);
while (true) {
int read = tokenizer.nextToken();
if (read == StreamTokenizer.TT_EOF) break; // detect EOF
int from = (int)tokenizer.nval;
tokenizer.nextToken();
int to = (int)tokenizer.nval;
tokenizer.nextToken();
int amount = (int)tokenizer.nval;
// Use the from/to/amount
// YOUR CODE HERE
}
}
catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
/*
Processes one file of transaction data
-fork off workers
-read file into the buffer
-wait for the workers to finish
*/
public void processFile(String file, int numWorkers) {
}
/*
Looks at commandline args and calls Bank processing.
*/
public static void main(String[] args) {
// deal with command-lines args
if (args.length == 0) {
System.out.println("Args: transaction-file [num-workers [limit]]");
System.exit(1);
}
String file = args[0];
int numWorkers = 1;
if (args.length >= 2) {
numWorkers = Integer.parseInt(args[1]);
}
// YOUR CODE HERE
}
}