need help with concurrent.ExecutorService

user00_at_hotmail.com
Date: 02/28/05


Date: 27 Feb 2005 17:20:46 -0800

I have a server application where clients connect directly and send
many commands to the server to process (typical server/client model). I
have something working but Im trying to be efficient as possible at the
same time. Im using ExecutorService for the thread pool and for each
command that comes in, I create a new Runnable class (to process the
command) and then I execute the Runnable against ExecutorService. I
dont know how efficient it is to create a Runnable class for each
command that is received. Here is some sample code....

ExecutorService es = Executors.newFixedThreadPool(25);

void commandRecieved(String cmd) {
     es.execute(new ProcessTask(cmd));
}

//Runnable class to process the command

class ProcessTask implements Runnable {

    String cmd;

    public MyTask(String cmd) {
      this.cmd = cmd;
    }

    public run() {
      MyServer.process(cmd);
    }

}

Is there a way around this? The task to do is the same but only
different in one parameter (the actual cmd string).

Since threads are fixed (persistent), I wonder if there is a way I can
associate a fixed Runnable task to each Thread and when I es.execute I
can actually just pass the cmd string only. I hope I am making sense?

Then again, maybe there is a better approach for my situation instead
of using ExecutorService? Maybe ExecutorService was intended for use
when you know there are going to be different types of tasks that is
going to be executed. Any help would be most appreciated.

Thanks in advance
Steve



Relevant Pages

  • need help with concurrent.ExecutorService
    ... many commands to the server to process. ... command) and then I execute the Runnable against ExecutorService. ... different in one parameter (the actual cmd string). ...
    (comp.lang.java)
  • [1/3] POHMELFS high performance network filesystem. Documentation.
    ... +POHMELFS: Parallel Optimized Host Message Exchange Layered File System. ... * Fast and scalable multithreaded userspace server. ... * Client is able to switch between different servers (if one goes down, ... +command (or set of commands, which is frequently used during data writing: ...
    (Linux-Kernel)
  • Re: WINSOCK Question.
    ... Which would be encoded as follows for the ITC: ... Dim strURL As String, strFormData As String ... This again indicates that the POST command is doing the same ... It sends the command to the server, ...
    (microsoft.public.vb.controls.internet)
  • [2/3] POHMELFS: Documentation.
    ... * Client is able to switch between different servers (if one goes down, ... Each transaction contains all information needed to process given command ... are asynchronous and are sent to the server during system writeback. ... +POHEMLFS is capable of full data channel encryption and/or strong crypto hashing. ...
    (Linux-Kernel)
  • Re: Explanation of macros; Haskell macros
    ... > server and I got to dictate the form of the commands and arguments. ... it boiled down to (funcall command client-session args). ... Let's assume there is a type "Session" for sessions. ... You don't need the first constraint, ...
    (comp.lang.python)