[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 482
  • Last Modified:

outputting java arraylist contents periodically

     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(); }

Open in new window

  • 2
1 Solution
blossomparkAuthor Commented:
looking at  the Timer class currently
blossomparkAuthor Commented:
Timer class seems to have potential...will study this and repost if having issues

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now