ankursaxena
Programmer
Hi, I have this piece of code which i dont know will work fine. I am still writting code, and dont have a way of testing, may be someone can tell me if I can remove an element which is in the iteration and then cont, if I cont, what will the next element be?
Thanks
Thanks
Code:
ListIterator iter = report_Thread.outStreams.listIterator();
ListIterator iter_sock = report_Thread.clientSockets.listIterator();
int o_count = 0;
while (iter.hasNext())
{
try
{
Socket sock = (Socket)iter_sock.next();
ObjectOutputstream oos = (ObjectOutputStream)iter.next();
if(sock.isConnected())
{
oos.writeChars(ids);
oos.writeChars(vals);
oos.flush();
}
else
{
//remove sock and steam
report_Thread.outStreams.remove(oos);
report_Thread.clientSockets.remove(sock);
AppConstants.traceln("Removed socket/stream from vectors because conn was closed.");
}
}
catch(Exception exc)
{
AppConstants.traceln("Exception occured while sending to socket " + o_count);
exc.printStackTrace(AppConstants.log_file);
}