Run loop every second java
<pre><code>int delay = 1000; // delay for 1 sec. 
int period = 10000; // repeat every 10 sec. 
Timer timer = new Timer(); 
timer.scheduleAtFixedRate(new TimerTask() 
    { 
        public void run() 
        { 
            displayData();  // display the data
        } 
    }, delay, period);  
</code></pre>

<p>And other:</p>

<pre><code>while(needToDisplayData)
{
    displayData(); // display the data
    Thread.sleep(10000); // sleep for 10 seconds
}   
</code></pre>

<p>Both of them doesn't work (application is force closed). What other options I can try?</p>
