Source Code : Inner self run threads
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Inner self run threads

public class InnerSelfRunMain extends Object {
private Thread internalThread;
private volatile boolean noStopRequested;
public InnerSelfRunMain() {
// add your code here ...
System.out.println("initializing...");
noStopRequested = true;
Runnable r = new Runnable() {
public void run() {
try {
runWork();
} catch (Exception x) {
// in case ANY exception slips through
x.printStackTrace();
}
}
};
internalThread = new Thread(r);
internalThread.start();
}
private void runWork() {
while (noStopRequested) {
System.out.println("in runWork() - still going...");
try {
Thread.sleep(700);
} catch (InterruptedException x) {
Thread.currentThread().interrupt(); // re-assert interrupt
}
}
}
public void stopRequest() {
noStopRequested = false;
internalThread.interrupt();
}
public boolean isAlive() {
return internalThread.isAlive();
}
public static void main(String[] args) {
InnerSelfRunMain sr = new InnerSelfRunMain();
try {
Thread.sleep(3000);
} catch (InterruptedException x) {
}
sr.stopRequest();
}
}
Thank with us