I have encountered a problem while implementing the following requirement,
My requirement:- I have two threads Thread_1 and Thread_2.
Thread_2 performs TASK which can?t be implemented or performed in loop as it is not a single functionality to achieve.
Thread_1 should start the Thread_2 and Thread_2 needs to be stopped after a pre-defined time, say ?5 minutes? only in case of Thread_2 has not completed the TASK that it was executing.
I am trying to meet a requirement by following approach
class Thread_2 extends Thread
{
public void run(){
---
---
---
//TASK, tight bound. here for() = =TASK
for (int i=0;i<=100000;i++ )
{
// out of my scope to handle here
}
//end of TASK
-----
}
}
class Thread_1 extends XYZ
//should extend; XYZ implements java.lang.Runnable
{
-----
Public viod run(){
Therad_2 obj2 = new Therad_2();
------
th.start();
// Here is the PROBLEM. I have to stop the thread ?obj2? after some ?X? time means obj2 thread should run only for ?X? time. In short I got to kill the thred.
}// end run()
}// end Thread_1