Aniket Dutta
Aniket Dutta

Reputation: 175

twitter4j: Running in asynchrounous mode

i have list of twitter user ids in a file. And i am required to collect tweets of all the users in that file. Currently i am able to fetch tweets of all users. But i need to run is code forever. Currently i am doing something like this

while(true)  //run forever
{
       open(user ids file);
       while(there is more ids in file)
       {
             long id = readIDFromFile(file);
             List<Status> statuses = getTweetsForUser(id);
             appendListToTweetFile(statuses);                 
       }
       close(user ids file);
}

The reason i want to run it forever so that if there is any new tweet posted by any user i am able to record it. My question is is there a better way to run this code forever, I know keeping the code in infinite loop is not a good idea!!!

Upvotes: 0

Views: 49

Answers (1)

Daan Luttik
Daan Luttik

Reputation: 2855

You want to use a timer object which calls a method containing this function (without the while loop). this way you can keep updating the tweets without draining battery and cpu cycles like your doing here.

Upvotes: 1

Related Questions