thread question

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jul 2008
Posts: 20
Reputation: stewie griffin is an unknown quantity at this point 
Solved Threads: 0
stewie griffin stewie griffin is offline Offline
Newbie Poster

thread question

 
0
  #1
Jun 13th, 2009
Hi,
I have java code, in the code there is about 5 lines that I wont to open in new Thread, I don't wont to crate all new class for 5 lines , can I can I implement the Thread inside the method without new class?
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,713
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 229
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: thread question

 
0
  #2
Jun 13th, 2009
You can have the class extend the Thread class.
If you don't want to change the code of the old class though you can try to create a new one that extends the old and implements the Runnable interface:

Runnbale

  1. public NewClass extends OldClass implements Runnable {
  2.  
  3. public void run() {
  4. ......
  5. }
  6. }
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 1,016
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 150
JamesCherrill JamesCherrill is offline Offline
Veteran Poster

Re: thread question

 
0
  #3
Jun 13th, 2009
You can use an anonymous inner class. Something like:
  1. new Thread(){
  2. public void run() {
  3. // some lines of code
  4. }
  5. }.start();
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 20
Reputation: stewie griffin is an unknown quantity at this point 
Solved Threads: 0
stewie griffin stewie griffin is offline Offline
Newbie Poster

Re: thread question

 
0
  #4
Jun 13th, 2009
tnx it was exactly what i was locking for...
im marking as solved...
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC