Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. //NOTE: this isn't the full Stream class, but contains stuff you should add
  2. //on to your existing class.
  3. public class Stream extends Thread {
  4.  
  5.     private boolean triggerStartCrawling = false;
  6.     private Thread crawlingThread = ...;   
  7.  
  8.     public void run() {
  9.         while(true) {
  10.             if(triggerStartCrawling) {
  11.                 triggerStartCrawling = false;
  12.                 System.out.println("Started crawling!");
  13.                 //Start crawling
  14.                 crawlingThread.start();
  15.             }
  16.             //Hopefully, you understand the idea here- constantly check for a boolean being true, in which case execute
  17.             //some code, but if not, simply try again. You can do this with other operations as well.
  18.             //The crawling code can be encased within another thread, so it is simple to stop it at any time with      //java.lang.Thread.join()
  19.         }
  20.     }
  21.  
  22.     public void triggerStartCrawling() {
  23.         triggerStartCrawling = true;
  24.     }
  25.    
  26.     public void stopCrawling() throws InterruptedException {
  27.         crawlingThread.join();
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement