Problem with my Java Chat

C

Christoph Hager

Hello

I have a problem with my Java Chat. It will not let anyone connect
after something between 3000 to 8000 connections (NOT simultaneous
of course).
When it hangs you cannot connect as a new client. All the old clients
can still chat - he will just not accept new connections.
I posted the relevant source below. He will hang after writing 'Pos1'
into the logfile. This means he will hang after creating a new object
- before calling its constructor.

Ich use green_threads. Could this cause the problem?


Greetings
Christoph


---------------
ChatDaemon.java
---------------

ChatServer allocThread(Socket s) {
// freien Slot suchen:
int i=0;
if(numClients<maxClients) {
logIt("Neuer Chatclient Nummer: "+numClients);
ChatServer ct=new ChatServer(s, sharedMsg,
numClients, this);
chatters[numClients]=ct;
t[numClients]=new Thread(ct);
t[numClients].start();
numClients++;
return ct;
}
else {
// alten slot recyclen:
logIt("suche nach freiem slot");
while (i<maxClients) {
if (!chatters.alive()) {
logIt("Pos1");
ChatServer ct=new
ChatServer(s, sharedMsg, i, this);
chatters = null;
logIt("Pos2");
System.gc();
chatters=ct;
logIt("Pos3");
t.stop();
t = null;
logIt("Pos4");
System.gc();
t=new Thread(ct);
t.start();
logIt("Pos5");
logIt("Port recycled:
"+i+"\n");
return ct;
}
i++;
}
logIt("nix freies gefunden");
return null;
}
}


---------------
ChatServer.java
---------------
public ChatServer(Socket s,SharedMsg sm,int idx, ChatDaemon
cd) {
this.cd = cd;
index = idx;
sharedMsg = sm;
socket = s;
logIt("ChatServer Pos1");
try {

Class.forName("org.gjt.mm.mysql.Driver").newInstance();

conx=DriverManager.getConnection("jdbc:mysql://mysql:3306/premium?user=streng&password=geheim");
}
catch(Exception e) {
logIt("ChatServer Pos1 Error");
System.out.println("Fehler bei
Datenbankverbindung");
}
logIt("ChatServer Pos2");
try {
input=new
DataInputStream(socket.getInputStream());
logIt("ChatServer Pos3");
output=new
PrintStream(socket.getOutputStream(),true);
logIt("ChatServer Pos4");
}
catch(IOException e) {
System.out.println("Abnormal chat server
socket condition 1:"+e);;
logIt("ChatServer Pos4 ERROR");
}
}
 
S

Sanjay Goel

Christoph said:
Hello

I have a problem with my Java Chat. It will not let anyone connect
after something between 3000 to 8000 connections (NOT simultaneous
of course).
When it hangs you cannot connect as a new client. All the old clients
can still chat - he will just not accept new connections.
I posted the relevant source below. He will hang after writing 'Pos1'
into the logfile. This means he will hang after creating a new object
- before calling its constructor.

Ich use green_threads. Could this cause the problem?


Greetings
Christoph
<snip>
Are u closing all the dead connections ??
Sanjay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top