I have a Class
which implements Runnable
. I am using this Class in a thread and am trying to pause it and then restart it again using some sort of a boolean
flag. This is my code:
class pushFiles implements Runnable{
private volatile boolean running = true;
public void run () {
.
. some code
.
while (running){
.
. more code
.
}
}
public void stop() {
running = false;
}
public void start() {
running = true;
}
};
I am trying to pause the thread using the stop
method and restart it using the start
method.
The stop
method actually stops/pauses the thread, but the start
method does not make it run again.
When initializing the thread I use:
runnable = new pushFiles();
thread = new Thread(runnable);
thread.start();
What am I doing wrong? Is it possible to unpause a thread? How can I do it?