blossompark
asked on
outputting java arraylist contents periodically
Hi,
have a client server application where multiple clients send string data (eg football scores) to a server and the server then outputs the data. Currently my server stores the data in an ArrayList and outputs the data as it gets it.
What i want to happen is that the server outputs its gathered data every 30 seconds..
i was thinking of introducing a sleep method in the run method (see run method below) but i dont think that can work..
Is there some way to introduce a "timer" that calls a method every 30 seconds that then outputs the contents of the ArrayList?
I have attached my client and server source files...thanks
public void run() {
ArrayList<String> storedScores =new ArrayList<String>();
String message;
try {
while ((message = reader.readLine()) != null) {
// System.out.println("Latest Score: " + message);
storedScores.add(new String(message));
// tellEveryone(message);
Iterator<String> itr = storedScores.iterator();
while( itr.hasNext() ) {
String str = itr.next();
System.out.println( str );
}
}
} catch (Exception ex) { ex.printStackTrace(); }
}
ClientScoresUpdater2.txtScoresServer2.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER