Skip to content

Commit ab18ea6

Browse files
author
Sandy W
committed
changed time measurement, added benchmark boolean
1 parent f295dbd commit ab18ea6

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

client/Client.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class Client {
2525

2626
// this AtomicLong is used to keep track of the current # of running threads
2727
private static AtomicLong runningThreads = new AtomicLong(0);
28+
private static boolean benchmark = false;
2829

2930
public static void main(String[] args) {
3031
int menuSelection = 0;
@@ -50,6 +51,7 @@ else while (menuSelection != 8) {
5051
// if 7, ask which command should be run in the benchmark mode
5152
// and how many connections to create
5253
if (menuSelection == 7) {
54+
benchmark = true;
5355
menuSelection = benchmarkMenu();
5456
numProcesses = numProcessesMenu();
5557
}
@@ -62,7 +64,7 @@ else while (menuSelection != 8) {
6264
// make a new thread, tell it the hostname to connect to
6365
// and the command to run. It is also passed the totalTime object,
6466
// so it can record how much time its command took to complete
65-
thrd = new Thread(new ClientThread(args[0], menuSelection, totalTime, (numProcesses == 1), runningThreads));
67+
thrd = new Thread(new ClientThread(args[0], menuSelection, totalTime, benchmark, runningThreads));
6668
thrd.start(); // start the thread
6769
list.add(thrd); // add the thread to the end of the linked list
6870

client/ClientThread.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ public void run() {
4848
PrintWriter out = null;
4949
BufferedReader input = null;
5050
try {
51-
// get the current time (before connecting to the server)
52-
startTime = System.currentTimeMillis();
53-
5451
//creates a new Socket object and names it socket.
5552
//Establishes the socket connection between the client & server
5653
//name of the machine & the port number to which we want to connect
@@ -64,6 +61,9 @@ public void run() {
6461
//opens a BufferedReader on the socket
6562
input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
6663
if (printOutput) System.out.println("\nRequesting output for the '" + menuSelection + "' command from " + hostName);
64+
65+
// get the current time (before sending the request to the server)
66+
startTime = System.currentTimeMillis();
6767

6868
// send the command to the server
6969
out.println(Integer.toString(menuSelection));

0 commit comments

Comments
 (0)