Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

thread monitor program

 
soheb khan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20775
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way to check status of threads of one class from other class???how to write that classes
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic