AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

need help with concurrent.ExecutorService

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> JVM, native methods and hardware
View previous topic :: View next topic  
Author Message
user00@hotmail.com
Guest





PostPosted: Mon Feb 28, 2005 1:20 am    Post subject: need help with concurrent.ExecutorService Reply with quote



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

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> JVM, native methods and hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.