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?

Recommended Answers

All 3 Replies

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

public NewClass extends OldClass implements Runnable {
   
  public void run() {
      ......
  }
}

You can use an anonymous inner class. Something like:

new Thread(){
  public void run() {
     // some lines of code
   }
}.start();

tnx it was exactly what i was locking for...
im marking as solved...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.