[IG] seemingly incorrect adive to call start() instead of run()

In following overloaded run() method, IG says that start() should be
called. This does not really make sense when super.run() is being
called, no?

public void run() {
NDC.push(serverName);
try {
super.run();
} finally {
NDC.pop();
}
}

--
Barry Kaplan
bkaplan@integratedtrading.com


2 comments

Perfectly correct as per java rules, but there are some semantics or design considerations or whatever you call it. "run() shoule not be invoked directly"

I feel that
IG is perfectly suggesting that you are making a mistake.

May be you can change your design to something like
class T1 extends Thread {

public void run() {
doSomething();
}
}

class T2 extends T1 {
public void run() {
NDC.push(serverName);
try {
super.doSomething();
} finally {
NDC.pop();
}
}
}

0


The basic idea behind that rule is that calling "run()" on a thread is usually a mistake, when you actually meant "start()". No deep semantic reasoning here, just catching a common stupid mistake. Feel free to ignore in those rare cases where "run()" is actually the correct semantics.

--Dave Griffith

0

Please sign in to leave a comment.