简体   繁体   中英

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!!!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM