943,696 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 393
  • Java RSS
Jun 13th, 2009
0

thread question

Expand Post »
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?
Similar Threads
Reputation Points: 64
Solved Threads: 1
Light Poster
stewie griffin is offline Offline
35 posts
since Jul 2008
Jun 13th, 2009
0

Re: thread question

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

Java Syntax (Toggle Plain Text)
  1. public NewClass extends OldClass implements Runnable {
  2.  
  3. public void run() {
  4. ......
  5. }
  6. }
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,258 posts
since Dec 2007
Jun 13th, 2009
0

Re: thread question

You can use an anonymous inner class. Something like:
Java Syntax (Toggle Plain Text)
  1. new Thread(){
  2. public void run() {
  3. // some lines of code
  4. }
  5. }.start();
Featured Poster
Reputation Points: 1907
Solved Threads: 950
Posting Expert
JamesCherrill is offline Offline
5,767 posts
since Apr 2008
Jun 13th, 2009
0

Re: thread question

tnx it was exactly what i was locking for...
im marking as solved...
Reputation Points: 64
Solved Threads: 1
Light Poster
stewie griffin is offline Offline
35 posts
since Jul 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Database
Next Thread in Java Forum Timeline: Hash Tables & Files





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC