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 3238640
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:52:39+00:00 2026-05-17T17:52:39+00:00

I wrote a Java scheduler, every hour using: new SAXBuilder().build(new URL(xxx)); or HttpConnection.connect(new URL(xxx));

  • 0

I wrote a Java scheduler, every hour using:

new SAXBuilder().build(new URL(xxx));

or

HttpConnection.connect(new URL(xxx)); // jsoup library code

to get a big XML/HTML file.

My server maximum bandwidth limit is 2Mbits.

When this Java schedule code runs, I use over 2Mbits of bandwidth. (check it out)

So every time a user visits my server it is too slow.

How do I limit my Java schedule to use lower bandwidth?
(ex. 500Kbits)

I am using Ubuntu server.

  • 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-05-17T17:52:40+00:00Added an answer on May 17, 2026 at 5:52 pm

    There’s no elegant way to do this.

    A simple but inelegant way would be to write a Java stream wrapper that limits the rate at which bytes are read from the wrapped Stream. For instance, if you wanted to limit to 1000 bytes per second, the int read() method could be implemented as follows:

    Stream in;
    long timestamp = System.currentTimeInMillis();
    int counter = 0;
    int INTERVAL = 1000; // one second
    int LIMIT = 1000; // bytes per INTERVAL
    
    ...
    
    /**
     * Read one byte with rate limiting
     */
    @Override
    public int read() {
        if (counter > LIMIT) {
            long now = System.currentTimeInMillis();
            if (timestamp + INTERVAL >= now) {
                Thread.sleep(timestamp + INTERVAL - now);  
            }
            timestamp = now;
            counter = 0;
        }
        int res = in.read();
        if (res >= 0) {
            counter++;
        }
        return res;
    }
    

    It is worth noting that throttling rates like this can have negative as well as positive effects. On the negative side:

    • It ties down resources on the server side for longer. In this case, we are talking about the Java thread that is handling the download, and memory in kernel space is used to buffer received network packets until the application reads them.

    • It may also lead to more network traffic. The problem is that this kind of throttling will disrupt the smooth flow of packets. The server will only buffer a relatively small number of packets, and when that number is exceeded, it has to tell the client to STOP for now. This requires extra signalling packets (ACKs) and there will probably be data packets dropped in the process. Eventually, those data packets will need to be retransmitted.

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

Sidebar

Related Questions

Using Swing in Java I wrote a form containing radio buttons, text fields and
I wrote a Java application to add articles to a Joomla site. I'm using
I wrote custom java proposals contributor. It works fine when using Java Proposals advanced
I wrote a java program that using the SVNKit. The timestamp of checked out
I'm trying to port an application I wrote in java to javascript (actually using
I wrote a Java program to add and retrieve data from an MS Access.
i wrote a java app that communicates and stores data in oracle; my question
I'm converting an algorithm I wrote in Java to Objective-C. In java the BigDecimal
I set up Open-xchage(wrote on Java) on openSUSE and installed SOAP extension on it.
I just want to output current and I wrote import java.util.*; at beginning, and

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.