outputting java arraylist contents periodically

Posted on 2009-12-29
Last Modified: 2012-05-08

     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 =;

         System.out.println( str );





            } catch (Exception ex) { ex.printStackTrace(); }


Open in new window

Question by:blossompark

    Author Comment

    looking at  the Timer class currently

    Accepted Solution

    Timer class seems to have potential...will study this and repost if having issues

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now