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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:26:07+00:00 2026-06-02T21:26:07+00:00

I have a class that basically has two methods the first one takes a

  • 0

I have a class that basically has two methods the first one takes a String (name of a file) and a thread:

public static void readFile(String s, Thread t){
    Runnable read = new Runnable() {
      public void run() {
          //SOME CODE



}
        t = new Thread(read);
    t.start();

}

The second method is a main method that asks the user for input and then uses that input to set a few things (like if the number of threads is just one or if it is equal to the number of objects in a list).

public static void main(String[] args){
  //SOME CODE

  for(Object x: ListOfObjects){
  //t1 is the same thread each time if one thread requested, otherwise t1 is a different thread each time
  readFromFile(textFileString, t1);
  //SOME CODE
}

If the user were to request 5 threads (for 5 items in a list), how could the above be modified for that? Currently, my main method has a loop (for the number of items in the list) and then the first method is called for each iteration in the loop. Is there a way to take the number of threads requested by the user, and initiate/start them in the first method all at once instead of one at a time and calling the method?

  • 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-02T21:26:08+00:00Added an answer on June 2, 2026 at 9:26 pm

    Implement the Runnable interface. I tried
    this and it seems to work:

    class StringThread implements Runnable
    {
        private String str;
        private int num;
    
        StringThread(String s, int n)
        {
            str  = new String (s);
            num =n; 
        }
    
        public void run ( )
        {
            for (int i=1; i<=num; i++)
                System.out.print ("THREAD NAMED: " + str+"  I IS: " +
                                                   i + "\n"); 
        }
    }
    
    //IN the main program:
    
    StringThread t1 = new StringThread ("THR-1",100);
    new Thread(t1). start ( );    
    StringThread t2 = new StringThread ("THR-2",200);
    new Thread(t2). start ( );   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm creating this class that has two buttons, one for logging in, and
I have a camera class that has two pointers as parameters: Camera::Camera( float fOVDeg,
I have a class that basically stores files in amazon s3. Here is what
I have a class that is its own activity that basically i use to
I'm testing a C++ class with a number of functions that all have basically
I have a Sinatra app that, boiled down, looks basically like this: class MyApp
I have class that represents users. Users are divided into two groups with different
I have a class that have three methods that have functionalities on Active Directory.
I'm writing an application which has two classes that provide basically the same functionality
I have a library class which contains two methods, say, Login() and NavigateToPage(). Now,

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.