0

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

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by stephy1
0

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.

0

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

0
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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.