Skip to main content

Many threads access chat applet, start very slow??

3 replies [Last post]
Joined: 2004-01-13

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.


Reply viewing options

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

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() {}});
for (Thread thread : threads) {

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.

Joined: 2005-08-10

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

Joined: 2005-08-10

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. :)