There is a cycle:
void someTask() { TimerTask task = new TimerTask() { public void run() { while (parseRep < 2) { Document doc = null; try { Connection.Response response = Jsoup.connect("http://mobayle.ru/aut.php") .method(Connection.Method.GET) .execute(); response = Jsoup.connect("http://mobayle.ru/login.php") .header("Content-Type","application/x-www-form-urlencoded;charset=UTF-8") .data("nick", loginAuth ,"pass", passAuth) .method(Connection.Method.POST) .timeout(30000).execute(); doc = Jsoup.connect("http://mobayle.ru").cookies(response.cookies()).get(); Element blockRega = doc.select("div.foot").first(); nav2Reg = blockRega.text(); Element usInfo = doc.select("div.nav1").first(); usName = usInfo.text(); Elements kollMess = doc.select("a[href*=new_mess] div.nav2 font[color=red]"); kollNewMess = kollMess.text(); System.out.println(kollNewMess); } catch (IOException e) { e.printStackTrace(); } Log.d(LOG_TAG, nav2Reg); } //while } }; new Timer().schedule(task, 1000, 10000); }
How can I make the repeated execution of the cycle begin only when 10 seconds have passed since the last execution? I would be grateful for the help.