Solved

Thread FAQ

Posted on 2004-08-10
6
195 Views
Last Modified: 2012-05-05
There is two ways to create threads:
1, implements Runnable
2, class MyThread extends Thread

i can call MyThread.join(); in the example 2 but how can i do that in example 1?

thanks
0
Comment
Question by:hawkly
  • 2
  • 2
  • 2
6 Comments
 
LVL 7

Assisted Solution

by:tomboshell
tomboshell earned 20 total points
ID: 11769944
The same way.  A runnable will not stand alone.  It will be given to a thread constructor.  Then you call the methods on the thread.

ex.
MyRunnable myRun = new MyRunnable();

Thread theThread = new Thread(myRun);
theThread.start();

Then it is all the same as you use in #2
0
 
LVL 35

Assisted Solution

by:girionis
girionis earned 20 total points
ID: 11770017
Just call join onthe thread's instcane:

myThread.join();
0
 
LVL 30

Accepted Solution

by:
mayankeagle earned 20 total points
ID: 11770440
If the class which implements Runnable has a Thread member which you're instantiating and over which you're calling the start () method, then expose it through a getter method:

public class Xyz extends Runnable
{
  private Thread t ;
 
  public Something ()
  {
    t = new Thread ( this ) ;
    t.start () ;

  } // end of constructor ()

  public void run ()
  {
    // the run () logic goes here

  } // end of run ()

  public Thread getHandle ()
  {
    return t ;

  } // end of getHandle ()

} // class definition over

Xyz obj = new Xyz () ;
obj.getHandle ().join () ;
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 35

Expert Comment

by:girionis
ID: 11838518
:)
0
 
LVL 7

Expert Comment

by:tomboshell
ID: 11838690
thanks!
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 11841027
;-)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now