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

  • Home
  • SEARCH
  • 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 6837973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:32:28+00:00 2026-05-26T23:32:28+00:00

I’m looking to implement Round Robin Load Balancing in Java on a very simple

  • 0

I’m looking to implement “Round Robin” Load Balancing in Java on a very simple HTTP web server.

Round Robin in this case would mean one HTTP request per port.

Say I have a webserver running 3 threads for 3 different ports each thread listening for a connection on that port. (This approach may be wrong.)

So a HTTP connection request comes in on a port, and say this needs 3 HTTP requests (a web page with 2 images for example). If this request came in on port 1234, for example, and my other 2 threads are sitting on 2 other ports doing nothing, how would I load balance this? So the first thread gets the first request, 2nd thread the next, 3rd the next, and back again. (If this is my correct understanding of round robin.)

  • 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-26T23:32:28+00:00Added an answer on May 26, 2026 at 11:32 pm

    You need two things :

    1) You need a data structure which will rotate between the ports, in order, forever. This is known as a “circular data structure”.

    2) You will need to ensure that the data structure is shareable between threads, that is, that when one thread starts using a port for doing something, the data structure is notified of the fact that that port is busy, and then the particular port is locked.

    A bare bones approach could be to use a synchronized circular queue here with locks in each of two slots.

    Once you add each port’s representative lock to the queue, you can have each thread lock that particular port while in use. Once the lock is released, the work can begin anew.

    So first, we will create the queue to have 2 locks init, and the server will have an iterator in the queue.

    When the request comes in – the thread will ask the server for a port. The server will check if the current (1st) slot is locked. If so , it will wait — when unlocked, it will asynchronously give the lock to the thread, and increment position in the queue. The thread will then lock this resource, process the request, and unlock it. Once the thread finishes processing, it will unlock the resource. Meanwhile, if the 2nd thread comes, the server is free to assign the 2nd port, if that port is free.

    Of course – there is a potential deadlock in your design here : if one thread never completes, the server will be stuck waiting for the lock to unlock before it increments to the next port.

    http://www.koders.com/java/fid13E588928D0C01917AC9C30E35D802BDBA546368.aspx?s=Queue#L23

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

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.