How to create java threads with multiple start and run signatures

Hi,

with reference to the following question

http://www.experts-exchange.com/questions/28784460/Triggering-a-shell-command-from-a-java-servlet-30-minutes-after-the-http-call.html

I need some examples on how the start and run methods can have different signatures

i.e how can I pass arguments to run() and start() without creating static variables
anshumaEngineeringAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
You implement Runnable and/or Callable. The classes you create and submit to the executor can have whatever members you need. Those would be filled by the ctor

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
anshumaEngineeringAuthor Commented:
Can you please attach some sample pseudo code
anshumaEngineeringAuthor Commented:
What is ctor
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
Basically, you define a custom Runnable class such as this (a simple example)...

public class SendEmailTask implements Runnable {
    private String to;
    private String message;

    public SendEmailTask(String to, String message) {
        this.to = to;
        this.message = message;
    }

    @Override
    public void run() {
        // Have your code to create and send your email, you can use the variables 'to' and 'message'
        //   to populate the email message
    }
}

Open in new window



And when your request comes in and you want to schedule your delayed task, you can do this (borrowing a bit from Doug's code in the previous question)...

m_executor.schedule(new SendEmailTask("joebloggs@gmail.com", "Hi Joe, Here is an email!!"), 1, TimeUnit.MINUTES);

Open in new window

dpearsonCommented:
:)

Doug
CEHJCommented:
You implement Runnable and/or Callable.
That, of course, should have said

You implement Runnable or Callable.

What is ctor
ctor == constructor
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.