| Author |
Execute thread from another class?
|
J Gib
Greenhorn
Joined: Jul 20, 2006
Posts: 5
|
|
Hey everyone, Heres my situation: I'm already extending Applet so extending Thread is not an option. I've already used the "Run()" method in the class i've been coding, but i need to run another thread which does something completely different: (Checks to see if a txt file has been changed every 60 seconds) -- since i can't have a second "Run" method in that class, im guessing that i need to make a second class with it's own Run() and somehow execute that method from my original class. Does that sound about right? if so, how do i do it?! I've been researching this for several days with no luck.. if anybody can help me out or possibly suggest some alternatives i would really appreciate it.
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24061
|
|
Hi, Welcome to JavaRanch! Yes, you can simply define a second class that implements Runnable, and just pass an instance of that to the Thread constructor instead of "this". new Thread(new MyOtherClass()).start(); If MyOtherClass needs access to parts of the main class, then you have several alternatives. The easiest one may be to simply use an inner class -- a class defined inside another class. The inner class has access to its outer class's private members.
|
[Jess in Action][AskingGoodQuestions]
|
 |
 |
|
|
subject: Execute thread from another class?
|
|
|