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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:30:58+00:00 2026-06-13T20:30:58+00:00

I still have some trouble wrapping my head around threads, and I’m trying to

  • 0

I still have some trouble wrapping my head around threads, and I’m trying to do this in the simplest way possible. I know that threads all have to have a run method they inherited from the Runnable class, but they can have additional methods as well, correct?

The reason being, I have a thread with some private variables and a run method. It calls it’s run function, and once it’s done, I want to reuse the thread with the exact same run method. It does exactly the same thing, just with different variables. So can I add something like a setArray method (the thread contains a private byte array) so I can just simply call run again with this new array, or is that not allowed. I guess to put it simply, it’d be something like

Thread thread = new MyThread();
thread.start();

// Check if the thread has finished in a non-blocking way
if (thread.isAlive() == false) {
    thread.setArray(newArray)
    thread.start();
}

Basically I only have a fixed number of threads and when the first thread is done running, I want to change the parameters a bit and have it run again. I don’t wan them to die, which seems to be what join does.

For the specific problem, I have say 4 threads, that each are give a set size block of a larger byte array. Each thread compresses that array with a Deflater and passes their result to a manager object that handles the synchronization. Once the first thread (as in the thread that got the first part of the array, not the first to finish) is done, it moves on to the next block not assigned to a thread.

I know thread pools are an option, but it seems a bit overkill plus I really don’t understand them (I’m still having trouble with just normal threads).

  • 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-13T20:30:59+00:00Added an answer on June 13, 2026 at 8:30 pm

    First, it is best to use the standard Thread class (don’t subclass it!) and put your application code into a class that implements Runnable. This makes it much easier to separate your application logic from the problem of managing the threads.

    Second you have to understand that a Thread object calls the run method just once. After the run method has returned (or terminated with an exception), the Thread object is dead, and cannot be brought back to life.

    So if you want to “reuse” Thread instances, you have to arrange that the run method is a loop that (somehow) waits for the next thing to be done. And before you know it you are implementing a thread pool.

    There is another (more “modern”) alternative to a thread pool. Create an ExecutorService instance, and use the submit() method to submit the Runnable instances for execution. The interface javadoc has a good usage example, using an executor service instance with a private thread pool. If you wanted to, you could reuse the Runnable instances, but generally it is simpler (and safer) to create new ones each time.

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

Sidebar

Related Questions

Having a bit of trouble wrapping my head around Qtimer this morning. Here's the
I have still having some CSS trouble with this and I cannot seem to
Ok I am still learning this... I have Googled and done some research but
I've just recently started using SQLAlchemy and am still having trouble wrapping my head
I am trying to install gitlist from github. I have some trouble installing it,
I know that people have had some trouble with undefined CssClass values when using
I am currently switching from AS3 to JavaScript. I still have some trouble with
I'm trying to work with special chars in URLs but I have some trouble
I have some trouble here, do you know Yahoo! News? I want to create
There might be similar questions but I still have some parts that I couldn't

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.