Skip to main content

Many threads access chat applet, start very slow??

3 replies [Last post]
nwa001
Offline
Joined: 2004-01-13
Points: 0

Anyone can help??

I am not a newbie, but I haven't seen this problem before. I started 80 threads in a chat applet, it starts real slow about 2-4 minutes, after that it gets better, occasionally as slow as 2-4 minutes.

Does anyone any experience on starting many threads at the same time, why it starts so slow, is it because the over head for many thread to start in one environment? does it represent the real case senario when many people access chat server at the same time.

Any suggestions are welcome, I will award duke dollars.

Thanks!
nwa001

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tackline
Offline
Joined: 2003-06-19
Points: 0

I suspect that it isn't starting the threads that takes the time, but something they do.

Here's a little test program:

class ThreadTime {
public static void main(String[] args) throws Exception {
java.util.List threads = new java.util.ArrayList();
for (int ct=0; ct<80; ++ct) {
Thread thread = new Thread(new Runnable() {public void run() {}});
thread.start();
threads.add(thread);
}
for (Thread thread : threads) {
thread.join();
}
}
}

My lowly Celeron gives:

$ time java ThreadTime

real 0m0.128s
user 0m0.075s
sys 0m0.041s

About a quarter of the second for the whole caboodle.

olsonje
Offline
Joined: 2005-08-10
Points: 0

Have you tried using the profiler in Netbeans, or whatever, to see what is using all that time?

olsonje
Offline
Joined: 2005-08-10
Points: 0

I'm not a threading guru or anything, but why are you starting 80 on a chat applet? Are you trying to do some peer-to-peer chat applet that each applet talks to all other applets with a max of 80 people using this chat system?

Just slightly confused. :)