| Author |
thread monitor program
|
soheb khan
Greenhorn
Joined: Aug 16, 2012
Posts: 3
|
|
I have an application in which I need to design a thread monitor program. ThreadAlive is the thread which monitors the request threads(Worker Threads).
Worker threads have to register themselves upon instantiating to ThreadAlive thread. Upon registration of the worker thread ThreadAlive has to monitor the worker threads. I have designed the ThreadAlive class and worker thread separately. I am not sure how do i register the worker thread to the ThreadAlive thread.
(Once worker Thread is register Threadalive will keep checking the status in particular timestamp .After time is expire it will through an event).
I am not sure how do i register the worker thread to the ThreadAlive thread whenever a worker thread starts it have to register with the name and the timestamp of it.
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16487
|
|
soheb khan wrote:Worker threads have to register themselves upon instantiating to ThreadAlive thread. Upon registration of the worker thread ThreadAlive has to monitor the worker threads. I have designed the ThreadAlive class and worker thread separately. I am not sure how do i register the worker thread to the ThreadAlive thread.
Well, then you haven't designed the ThreadAlive class. At least, not completely. You have identified a missing feature of the design, namely a method for registering a worker thread.
Clearly the signature of the missing method would be something like
That's assuming that your worker threads are instances of Thread, and that you don't need to throw any exceptions if problems occur in the registration, and so on... naturally you would adapt that to match your actual requirements.
|
 |
soheb khan
Greenhorn
Joined: Aug 16, 2012
Posts: 3
|
|
If there are two classes how can you check the first class thread is running from second class???
package threadpackage;
class Runner extends Thread {
@Override
public void run() {
System.out.println("soheb");
try {
sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public class Worker {
public static void main(String[] args) {
Runner runner1 = new Runner();
ThreadAlive th=new ThreadAlive();
th.register("runner1", 10000);
runner1.start();
}
}
this is my worker thread class i want check runner1 is alive or not from a different class
like
package threadpackage;
public class ThreadAlive{
public void register(String string,int time) {
System.out.println(string);
System.out.println(time);
// name.isAlive();
}
}
I actullay send the name and time stamp of the thread can we check the status of the thread from threadalive class or not
|
 |
soheb khan
Greenhorn
Joined: Aug 16, 2012
Posts: 3
|
|
|
Is there any way to check status of threads of one class from other class???how to write that classes
|
 |
Steve Luke
Bartender
Joined: Jan 28, 2003
Posts: 3090
|
|
soheb khan wrote:Is there any way to check status of threads of one class from other class???how to write that classes
Have you looked at the API for java.lang.Thread? (<-- that is a link...) I am most certain it would be helpful to do so.
|
Steve
|
 |
 |
|
|
subject: thread monitor program
|
|
|