Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //NOTE: this isn't the full Stream class, but contains stuff you should add
- //on to your existing class.
- public class Stream extends Thread {
- private boolean triggerStartCrawling = false;
- private Thread crawlingThread = ...;
- public void run() {
- while(true) {
- if(triggerStartCrawling) {
- triggerStartCrawling = false;
- System.out.println("Started crawling!");
- //Start crawling
- crawlingThread.start();
- }
- //Hopefully, you understand the idea here- constantly check for a boolean being true, in which case execute
- //some code, but if not, simply try again. You can do this with other operations as well.
- //The crawling code can be encased within another thread, so it is simple to stop it at any time with //java.lang.Thread.join()
- }
- }
- public void triggerStartCrawling() {
- triggerStartCrawling = true;
- }
- public void stopCrawling() throws InterruptedException {
- crawlingThread.join();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement