Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Threading should be managed by a ExecutorService #2

Merged
merged 1 commit into from

2 participants

Burcu Dogan Armagan Amcalar
Burcu Dogan

No description provided.

Burcu Dogan rakyll Making modifications to allow reuse of threads to handle client conne…
…ctions

Each request is handled by spawning a new thread and finished by
disconnecting. Modifying threads to be handled by a cached thread pool
to minimize the number of thread creation.
fd00a4b
Armagan Amcalar dashersw merged commit ff4f95b into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 9, 2012
  1. Burcu Dogan

    Making modifications to allow reuse of threads to handle client conne…

    rakyll authored
    …ctions
    
    Each request is handled by spawning a new thread and finished by
    disconnecting. Modifying threads to be handled by a cached thread pool
    to minimize the number of thread creation.
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 1 deletion.
  1. +5 −1 src/net/aib42/directserver/Server.java
6 src/net/aib42/directserver/Server.java
View
@@ -5,6 +5,8 @@
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.HashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicLong;
import net.aib42.directserver.CommandParser;
@@ -17,12 +19,14 @@
private AtomicLong nextClientId;
private CommandParser commandParser;
private HashMap<Byte, Module> modules;
+ private ExecutorService executor;
public Server()
{
nextClientId = new AtomicLong();
commandParser = new CommandParser(this);
modules = new HashMap<Byte, Module>();
+ executor = Executors.newCachedThreadPool();
}
/**
@@ -60,7 +64,7 @@ public void handleClientConnect(SocketChannel clientChannel)
}
Thread clientThread = new Thread(client, "Client #" + client.getId());
- clientThread.start();
+ executor.execute(clientThread);
}
/**
Something went wrong with that request. Please try again.