• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Problem Using ScheduledThreadPoolExecutor

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm coding a program which calls a servlet, gets Strings in return, and posts the Strings into an EditText.

The code works fine without using the ScheduledThreadPoolExecutor , but when I use it, debugging the servlet shows the request has arrived, and it returns a answer, yet the Android application never posts the String into the EditText.

I want the program to call the servlet every 1 second.
At the moment where the program needs to start polling, this code is activated:

Class data member :

private ScheduledThreadPoolExecutor timer = new ScheduledThreadPoolExecutor(1);

Code in class :

timer.scheduleAtFixedRate(new Runnable() {
public void run() {
try {
String[] recentEvents;
recentEvents = getAllEvents(); // Gets the strings from the servlet
if (recentEvents != null)
activateEvents(recentEvents); // Prints them to the EditText
} catch (IOException e) {
e.printStackTrace();
}
}
}, 100, 1000,TimeUnit.MILLISECONDS);
 
You’ll find me in my office. I’ll probably be drinking. And reading this tiny ad.
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic