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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:50:57+00:00 2026-06-04T10:50:57+00:00

Config File ThreadSize = 10 StartRange = 1 EndRange = 1000 I have a

  • 0

Config File

ThreadSize = 10
StartRange = 1
EndRange = 1000

I have a config file above in which I have number of threads I want to use and the client instance is able to use ID range from 1 to 1000 and suppose the client threads is set at 10, so each thread would have range of 100 id’s(basically by dividing end range with thread size) that it can use without stepping on other threads. so What I want is that each thread should use 100 id’s from that range without stepping on other threads- for example

Thread1 will use 1 to 100 (id's)
// generate a random number between 1 to 100 and keep on printing values until it has generated all the random values between 1 to 100
Thread2 will use 101 to 200 (id's)
// generate a random number between 101 to 200 and keep on printing values until it has generated all the random values between 101 to 200
Thread3 will use 201 to 300 (id's)
// generate a random number between 201 to 300 and keep on printing values until it has generated all the random values between 201 to 300

-----
----
Thread10 will use 901 to 1000
// generate a random number between 901 to 1000 and keep on printing values until it has generated all the random values between 901 to 1000

I know how to write a multithreading program, but not sure how should I divide the range between various threads.

public static void main(String[] args) {

    for (int i = 1; i <= threadSize; i++) {
        new Thread(new ThreadTask(i)).start();
    }
}


class ThreadTask implements Runnable {
    private int id;

    public ThreadTask(int id) {
    this.id = id;
    }

    public synchronized void run() {

    }
}
  • 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-04T10:50:58+00:00Added an answer on June 4, 2026 at 10:50 am

    Each thread gets N = (EndRange - StartRange + 1) / ThreadSize numbers.

    Thread number i gets range (StartRange + i*N) - (StartRange + i*N + N - 1).

    In your example N = (1000 - 1 + 1) / 10 = 100.

    Thread i = 0 would get range (1 + 0*100) - (1 + 0*100 + 100 - 1) = 1 - 100

    Thread i = 1 would get range (1 + 1*100) - (1 + 1*100 + 100 - 1) = 101 - 200

    …

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

Sidebar

Related Questions

I have an Application.config file, which a Unicode (as opposed to ANSI or UTF8)
I have a config file to which I nee to add a couple of
In the config file I have the variable defined as BackgroundColor = 0,0,0 Which
I have an app config file which declares globals using DEFINE: define('BASE_DOMAIN', 'localhost/...'); define('BASE_URL',
I have a config file in which I have keys and values, like this:
Say I have a config file in which I have paths to JSON properties.
I have a ccnet.config file which uses my login details to a tfs server.
I have a config file that I read using the RawConfigParser in the standard
In my applications web.config file I have a connection string stored. I encrypted it
I have a large config file (user) that i needed to go to the

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.