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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:19:37+00:00 2026-05-17T00:19:37+00:00

I’m working on a java project with my team at work. To summarize, we

  • 0

I’m working on a java project with my team at work. To summarize, we have a main class that has a method that instantiates and calls a “Save” class. This “Save” class saves files back to a server with a couple of constructors and a handful of visible and non-visible methods. The class is CPU-intensive and time-consuming which prevents the main application from displaying a progress bar dialog window letting the user know the status of the save. They asked me to modify the “Save” class in a way that it will spawn off it’s own thread so the rest of the main application can do the smaller tasks of displaying information to the user.

Here is a general concept of it:

class MainApp{  
    ...

    private void doSave()
    {
        Save s = new Save();
        StatusWindow sw = new StatusWindow();

        if save_this
          s.saveThis(sw);
        if save_that
          s.saveThat(sw);

        ...
    }
    ...
}

class Save{
   ...

   public void saveThis(StatusWindow s)
   {
       //alot of code
       s.update;

   }
   public void saveThat(StatusWindow s)
   {
       //alot of code
       s.update;
   }
   ... // some non-visible methods, even more code
 }

I’m am currently a novice with threads in Java, but I have a basic understanding of how they work. From what I understand, a class that implements Runnable, when it is instantiated as a new thread, the run() method is executed. The problem is, since there are different methods for different types of saves for different types of files, how do I implement these methods into the run() method? Is the run() method the only method that gets executed when the class is instantiated in a new thread and .start() is called on it?

What would be a good solution to this issue? Would the “Save” class need to be redesigned to have it implement Runnable?

If more details are needed, please let me know. Thanks for any insight!

Update: Thanks everyone for the help! These solutions will come in handy for the future.

  • 1 1 Answer
  • 1 View
  • 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-17T00:19:38+00:00Added an answer on May 17, 2026 at 12:19 am

    The simplest way is to make a runnable for each. Instead of parameters being passed into run, make them instance fields.

    class SaveThatCommand implements Runnable {
         private final StatusWindow s;
         //constructor that initializes s
         public void run() {
            //save that code
            s.update();
         }
    }
    

    An easier way to accomplish this, depending on your requirements, is to make an anonymous inner class

    public void doSave(final StatusWindow s) {
        if (saveThis) {
            Thread t = new Thread( new Runnable() {
                public void run() {
                   saveThis(s);
                }
            });
            t.start();
        }
        //...
    }
    

    And you’re slightly incorrect: the run method is executed when it is passed into the constructor of a Thread and then start() is called on that thread.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I have thousands of HTML files to process using Groovy/Java and I need to
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.