A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Certification
»
Programmer Certification (SCJP/OCPJP)
Author
Call Overload Version of Thread's run method
Lennie De Villiers
Greenhorn
Joined: Jul 17, 2009
Posts: 24
posted
Jan 19, 2010 04:28:33
0
Hi,
The Thread class expect a run() method (no arguments), but how can I let it call a overload method? like run(MyClassName aClass)
Regards,
Lennie
Minhaj Mehmood
Ranch Hand
Joined: Jan 22, 2007
Posts: 400
I like...
posted
Jan 19, 2010 04:39:49
0
well you can create your own overloaded method.
public void run(String str){}
but how you will tell to thread.start() to execute my own overloaded run method??
by default thread.start() will execute no-arg run() method!
SCJP6 96%
| SCWCD5 81% |
SCDJWS5 79%
rushikesh sawant
Ranch Hand
Joined: Dec 22, 2009
Posts: 65
posted
Jan 19, 2010 04:51:01
0
you have to call overloaded run method on that particular object. it can be done in run() method which the thread recognizes.
public void run(){ object.run(arg); }
SCJP 5.0 100%
Minhaj Mehmood
Ranch Hand
Joined: Jan 22, 2007
Posts: 400
I like...
posted
Jan 19, 2010 05:05:01
0
yeah you are right rushikesh sawant. now it will become any normal void method
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35446
9
posted
Jan 19, 2010 05:09:38
0
Something like this may do what you want:
private class MyThread implements Runnable { private String data; public MyThread (String param) { data = param; } public void run() { // do something with the value of "data" here ... } } ... Runnable run = new MyThread("that's some data"); run.start();
Android apps
–
ImageJ plugins
–
Java web charts
I agree. Here's the link:
http://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: Call Overload Version of Thread's run method
Similar Threads
I thought of a NullPointerException??
runnable
Run method question
Question about equals! help
run() method
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter