I have 3 threads. 3 are going to do a different tasks , so different run() methods. How to overload run() method?

Recommended Answers

All 4 Replies

You can't. As I have told you here, simply assign some instance variable in the constructor and have the run method do different things based on the value of that/those variables.

The only other way is to write three different classes.

Can you give a sample for assigning instance variables to constructor ?

class Bogus implements Runnable {
    String action;
    Bogus(String action) {
        this.action = action;
    }
    public void run() {
        if (action = "whatever") {
            // do something
        } else .... {
            // do something else
        }
    }
}

At this point you are not ready for threading.

Ok.Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.