Skip to content

Commit

Permalink
A2 finished.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Oct 21, 2013
1 parent 8f27893 commit fd00811
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/blatt2/ServerStop.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package blatt2;

import java.net.InetSocketAddress;
import javax.swing.JOptionPane;
import blatt1.ClientEndpoint;

public final class ServerStop implements Runnable {

private ThreadPooledPrimeServer server;
private ClientEndpoint endpoint;

public ServerStop(ThreadPooledPrimeServer server) {
this.server = server;
endpoint = new ClientEndpoint();
}

@Override
public void run() {
JOptionPane.showMessageDialog(null, "Press OK to stop server.");

server.exit = true;
endpoint.send(new InetSocketAddress("localhost", 4711), 1);
}

}
5 changes: 4 additions & 1 deletion src/blatt2/ThreadPooledPrimeServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public final class ThreadPooledPrimeServer {

private ExecutorService executor;
private final ServerEndpoint endpoint;

public volatile boolean exit;

private static final int MAX_THREADS = 2;
Expand All @@ -24,9 +25,11 @@ void run() {

new Thread(new ServerStop(this)).start();

while (!exit)
while (true)
{
ServerEndpoint.Request request = endpoint.blockingReceive();
if (exit)
break;
PrimeCalculator calc = new PrimeCalculator(endpoint, request);
executor.execute(calc);
}
Expand Down

0 comments on commit fd00811

Please sign in to comment.