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

The Archive Base Latest Questions

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

One of actions in Struts2 is using below code: java.util.concurrent.ExecutorService myservice = Executors.newSingleThreadExecutor(); myservice.execute(new

  • 0

One of actions in Struts2 is using below code:

java.util.concurrent.ExecutorService myservice = Executors.newSingleThreadExecutor();
myservice.execute(new myTask(user, "add"));

Here, myTask is inner class which implements Runnable interface.

Can I invoke the above code from other action class as well by passing parameter a shown below:

java.util.concurrent.ExecutorService myservice = Executors.newSingleThreadExecutor();
myservice.execute(new myTask(user, "delete"));

In Run method, I’ll check the action & if its add, perform some activity, if its update, perform other activity….

Also, from another 3rd action class, can I invoke the same above thread by passing another action, say “update”???

class myTask implements Runnable{
private User user = null;

private String action = null;

myTask(User user, String action){
    this.user = user;
    this.action = action;
}

public void run(){
        if (action.equals("add")) {
                           performAdd(user);
                    } else if (action.equals("delete")) {
                           performDelete(user);
                    }
    }

Thanks!

  • 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-28T00:32:17+00:00Added an answer on May 28, 2026 at 12:32 am

    No – Runnable.run doesn’t take any parameters, so how would you expect the “delete” part to be provided to you?

    Just use the first form – create the Runnable instance with all the information it needs to know so that it can do its work. Alternatively, I would probably create three different implementations of Runnable – one for add, one for delete, and one for update. If you want to do one of three things, why switch on data at execution time when you can use polymorphism?

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

Sidebar

Related Questions

How does one convert an empty string to an int using Struts2. When the
I am new t struts2. i built one page, that shows list of employees.
we are using Struts2 in our code and I have scenario where I need
hi I am new in Struts2 and want to send parameter from one action
I'm successfully using a redirect-action for one of my struts2 mapping files as follows:
I'm trying to access a SOAP service I don't control. One of the actions
How can one best test a controller action which receives a file upload using
In one of my Struts action I've got the following code in a method:
I am trying to implement ajax in jsp(avoid form submit) using struts2. I used
I'm using Java at the core backend and JSP pages as GUI frontend. and

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.