Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8080629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:28:38+00:00 2026-06-05T16:28:38+00:00

I am trying to build connectors to twitter on top of twitter4j using java.

  • 0

I am trying to build connectors to twitter on top of twitter4j using java. One of the problems that Twitte4j doesn’t deal with and expects you to deal with is the ratelimit issue.

My approach to make the best out of twitter api using Twitter4j is to build multiple threads on top of it. I have tweets dump with nothing but tweet id and users with user ids in my database, I need my twitter threads to query twitter and update these tables whenever new information flows into them. So, I built two different threads, one that updates user table and one that updates tweets table. The user update thread is fairly easy to do, coz twitter supports querying up to 100 users in one go(users/lookup). The tweet thread, however, supports only one at a time (tweets/show). So, I have my ‘tweet update’ thread, start 5 more threads, wherein each thread goes and queries twitter and updates one single post at a time. This is where ratelimit comes into picture. So, at any moment, I have 6 threads running and querying TwitterService (my service class). These threads before querying always check if ratelimit has been hit, if yes, they go into sleep mode. So service method that threads invoke looks like this:

private synchronized void checkRateLimitStatus() {
        if (rateLimitHit) {
            try {
                logger.warn("RateLimit has been reached");
                wait(secondsUntilReset * 1000);
                rateLimitHit = false;
                secondsUntilReset = 0;

            } catch (InterruptedException ie) {
                ie.printStackTrace();
            }
            notifyAll();
        }
    }

The boolean rateLimitHit is set by Twitter4J listener, which checks the number of requests left. Once the count is zero, this bool is set to true. The code looks like this:

public synchronized void onRateLimitStatus(RateLimitStatusEvent evt) {
                RateLimitStatus status = evt.getRateLimitStatus();
                if (status.getRemainingHits() == 0) {
                    rateLimitHit = true;
                    secondsUntilReset = status.getSecondsUntilReset();
                }

            }

The problem with this is, say, I have 3 more queries left to Twitter, and the method checkRateLimitStatus() will return false for all the 6 queries (coz it has not been set, yet). So, all of the threads start coz the count is not zero yet. But, when first 3 threads are done with Twitter, the count would have reached zero and the rest of the three threads fail.

How do I solve this problem? How do I make these threads more reliable?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:28:40+00:00Added an answer on June 5, 2026 at 4:28 pm

    Assuming getting rate limit status is based on the same messaging with Twitter as other actions there’s always a lag that makes any attempts to bring reliability by checking this status unsuccessful. There’s always a chance when status will be out off date unless you operate in sync manner. I’d suggest you to try compute rate limit status locally and make all threads self-recoverable is case of error. Also using wait/notify mechanism is a good point for any repeatable actions from the perspective of CPU time wasting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to build a server program that receives file from client using
I am trying to build a simple GUI app in java that will show
I'm trying build a method which returns the shortest path from one node to
I'm trying build an App Engine connected Android application and am having some problems
Im trying to build call to action button on my site using jQuery. I
I'm trying to build a control logic that depends on the current gsp page
I'm trying to build a server that will handle many concurrent connections to iPhone
I am trying to build a custom dock for the galaxy nexus using the
I'm trying to build an html5 website that's multilingual and allows the user to
I'm trying to build a DSL and using a Global AST Transform to do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.