Java 类java.lang.Thread 实例源码

项目:RiskBots    文件:RunGame.java   
private void finish(IORobot bot1, IORobot bot2) throws InterruptedException
{
    bot1.finish();
    Thread.sleep(200);

    bot2.finish();
    Thread.sleep(200);

    Thread.sleep(200);

    // write everything
    // String outputFile = this.writeOutputFile(this.gameId, this.engine.winningPlayer());
    this.saveGame(bot1, bot2);

       System.exit(0);
}
项目:AppRTC-Android    文件:WebRtcAudioTrack.java   
private boolean stopPlayout() {
  Logging.d(TAG, "stopPlayout");
  assertTrue(audioThread != null);
  logUnderrunCount();
  audioThread.stopThread();

  final Thread aThread = audioThread;
  audioThread = null;
  if (aThread != null) {
    Logging.d(TAG, "Stopping the AudioTrackThread...");
    aThread.interrupt();
    if (!ThreadUtils.joinUninterruptibly(aThread, AUDIO_TRACK_THREAD_JOIN_TIMEOUT_MS)) {
      Logging.e(TAG, "Join of AudioTrackThread timed out.");
    }
    Logging.d(TAG, "AudioTrackThread has now been stopped.");
  }

  releaseAudioResources();
  return true;
}
项目:cordova-huawei-push    文件:CordovaHuaweiPush.java   
private void delToken(final CallbackContext callbackContext) {
   new Thread() {
       @Override
       public void run() {
           try {
               if (token != "" && null != huaweiApiClient) {
                   HuaweiPush.HuaweiPushApi.deleteToken(huaweiApiClient, token);
                   callbackContext.success();
               } else {
                   Log.w(TAG, "delete token's params is invalid.");
                   callbackContext.error("token not exists");
               }
           } catch (Exception e) {
                callbackContext.error("error occered when delete token");
                Log.e("PushLog", "delete token exception, " + e.toString());
           }
       }
   }.start();
}
项目:jdk8u-jdk    文件:DisplayChangeVITest.java   
public static void main(String[] args) throws Exception {
    DisplayChangeVITest test = new DisplayChangeVITest();
    GraphicsDevice gd =
        GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice();
    if (gd.isFullScreenSupported()) {
        gd.setFullScreenWindow(test);
        Thread t = new Thread(test);
        t.run();
        synchronized (lock) {
            while (!done) {
                try {
                    lock.wait(50);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
        }
        System.err.println("Test Passed.");
    } else {
        System.err.println("Full screen not supported. Test passed.");
    }
}
项目:openjdk-jdk10    文件:DisplayChangeVITest.java   
public static void main(String[] args) throws Exception {
    DisplayChangeVITest test = new DisplayChangeVITest();
    GraphicsDevice gd =
        GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice();
    if (gd.isFullScreenSupported()) {
        gd.setFullScreenWindow(test);
        Thread t = new Thread(test);
        t.run();
        synchronized (lock) {
            while (!done) {
                try {
                    lock.wait(50);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
        }
        System.err.println("Test Passed.");
    } else {
        System.err.println("Full screen not supported. Test passed.");
    }
}
项目:openjdk9    文件:DisplayChangeVITest.java   
public static void main(String[] args) throws Exception {
    DisplayChangeVITest test = new DisplayChangeVITest();
    GraphicsDevice gd =
        GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice();
    if (gd.isFullScreenSupported()) {
        gd.setFullScreenWindow(test);
        Thread t = new Thread(test);
        t.run();
        synchronized (lock) {
            while (!done) {
                try {
                    lock.wait(50);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
        }
        System.err.println("Test Passed.");
    } else {
        System.err.println("Full screen not supported. Test passed.");
    }
}
项目:react-native-audio-toolkitTemp    文件:AudioRecorderModule.java   
private WritableMap errObj(final String code, final String message) {
    WritableMap err = Arguments.createMap();

    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
    String stackTraceString = "";

    for (StackTraceElement e : stackTrace) {
        stackTraceString += e.toString() + "\n";
    }

    err.putString("err", code);
    err.putString("message", message);
    err.putString("stackTrace", stackTraceString);

    Log.e(LOG_TAG, message);
    Log.d(LOG_TAG, stackTraceString);

    return err;
}
项目:react-native-audio-toolkitTemp    文件:AudioPlayerModule.java   
private WritableMap errObj(final String code, final String message, final boolean enableLog) {
    WritableMap err = Arguments.createMap();

    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
    String stackTraceString = "";

    for (StackTraceElement e : stackTrace) {
        stackTraceString += e.toString() + "\n";
    }

    err.putString("err", code);
    err.putString("message", message);

    if (enableLog) {
        err.putString("stackTrace", stackTraceString);
        Log.e(LOG_TAG, message);
        Log.d(LOG_TAG, stackTraceString);
    }

    return err;
}
项目:murmur    文件:RangzenServiceTest.java   
/**
 * Test that starting the service is idempotent (only the first one counts).
 */
@Test
public void callingOnStartCommandMultipleTimes() throws Exception {
  // Sleep briefly to avoid racing with the first background task.
  Thread.sleep(AVOID_BACKGROUND_TASK_RACE_SLEEP_TIME);

  Date startTime = service.getServiceStartTime();
  int backgroundRunCount = service.getBackgroundTasksRunCount();
  Intent intent = new Intent(Robolectric.application, RangzenService.class);
  service.onStartCommand(intent, 0, startId);
  startId++;

  assertEquals("Start time changed calling onStartCommand again", 
          startTime, service.getServiceStartTime());
  assertEquals("Background run count changed calling onStartCommand again", 
          backgroundRunCount, service.getBackgroundTasksRunCount());
}
项目:jdk8u_jdk    文件:DisplayChangeVITest.java   
public static void main(String[] args) throws Exception {
    DisplayChangeVITest test = new DisplayChangeVITest();
    GraphicsDevice gd =
        GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice();
    if (gd.isFullScreenSupported()) {
        gd.setFullScreenWindow(test);
        Thread t = new Thread(test);
        t.run();
        synchronized (lock) {
            while (!done) {
                try {
                    lock.wait(50);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
        }
        System.err.println("Test Passed.");
    } else {
        System.err.println("Full screen not supported. Test passed.");
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:DisplayChangeVITest.java   
public static void main(String[] args) throws Exception {
    DisplayChangeVITest test = new DisplayChangeVITest();
    GraphicsDevice gd =
        GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice();
    if (gd.isFullScreenSupported()) {
        gd.setFullScreenWindow(test);
        Thread t = new Thread(test);
        t.run();
        synchronized (lock) {
            while (!done) {
                try {
                    lock.wait(50);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
        }
        System.err.println("Test Passed.");
    } else {
        System.err.println("Full screen not supported. Test passed.");
    }
}
项目:react-native-audio-toolkit    文件:AudioRecorderModule.java   
private WritableMap errObj(final String code, final String message) {
    WritableMap err = Arguments.createMap();

    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
    String stackTraceString = "";

    for (StackTraceElement e : stackTrace) {
        stackTraceString += e.toString() + "\n";
    }

    err.putString("err", code);
    err.putString("message", message);
    err.putString("stackTrace", stackTraceString);

    Log.e(LOG_TAG, message);
    Log.d(LOG_TAG, stackTraceString);

    return err;
}
项目:react-native-audio-toolkit    文件:AudioPlayerModule.java   
private WritableMap errObj(final String code, final String message, final boolean enableLog) {
    WritableMap err = Arguments.createMap();

    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
    String stackTraceString = "";

    for (StackTraceElement e : stackTrace) {
        stackTraceString += e.toString() + "\n";
    }

    err.putString("err", code);
    err.putString("message", message);

    if (enableLog) {
        err.putString("stackTrace", stackTraceString);
        Log.e(LOG_TAG, message);
        Log.d(LOG_TAG, stackTraceString);
    }

    return err;
}
项目:netclip    文件:Clipboard.java   
public void setClipboardTextAndClean(String text) {
    Log.i("netclip", "Clipboard.setClipboardText - " + text);
    this.stopCurrentCleanThread();
    this.continueCleanThread = true;
    this.androidClipboard.setPrimaryClip(
        ClipData.newPlainText("netclip", text)
    );
    this.currentCleanRunnable = new ClipboardCleanRunnable();
    this.currentCleanThread = new Thread(this.currentCleanRunnable);
    Log.i("netclip", "Clipboard.setClipboardText - starting new clipboard clean thread");
    this.currentCleanThread.start();

    Message message = this.handler.obtainMessage();
    message.obj = "Copied to clipboard";
    message.sendToTarget();
}
项目:netclip    文件:Clipboard.java   
@Override
public void run() {
    Log.i("netclip", "ClipboardCleanRunnable.run");
    int k = 0;
    while (k <= 15 * 10 && this.replaced == false) {
        Log.i("netclip", "ClipboardCleanRunnable.run - iteration");
        try {
            Thread.sleep(100);
            k++;
        } catch (InterruptedException ex) { }
    }
    if (this.replaced == false) {
        Log.i("netclip", "ClipboardCleanRunnable.run - cleaning clipboard");
        Clipboard.getInstance(null).reset();
    }
    Log.i("netclip", "ClipboardCleanRunnable.run - finished execution");
}
项目:dls-repository-stack    文件:HarvestManager.java   
private boolean interruptIngestorThread(String collectionId)
{
    ConcurrentHashMap<String, Thread> ingestorThreads = null;
    try {
        ingestorThreads = this.getIngestorThreads();
    } catch (Exception e) {
        return false;
    }
    if(ingestorThreads.containsKey(collectionId))
    {
        // That means it is still alive
        Thread ingestorThread = ingestorThreads.get(collectionId);
        if(ingestorThread.isAlive())
        {
            ingestorThread.interrupt();
            return true;
        }
    }
    return false;
}
项目:dls-repository-stack    文件:HarvestManager.java   
public void interruptAllIngestorThreads()
{
    try 
    {
        for(Thread ingestorThread: this.getIngestorThreads().values())
        {
            if(ingestorThread.isAlive())
            {
                ingestorThread.interrupt();
            }
        }

        if(this.reharvesterThread!=null && this.reharvesterThread.isAlive())
            this.reharvesterThread.interrupt();

    // Give the threads five seconds to try to clean themselves up

        Thread.sleep(5000);
    }
    catch (Exception e1) {}
}
项目:uni    文件:Flappy.java   
public static void main(String args[]){
    Game g = new Game(20,40,1);
    Input in = new Input();
    in.start();
    while(g.play){
        try{
            g.refresh();        
            if(in.getState() != Thread.State.WAITING){
                g.b.y--;
            }else{g.b.y++;}
            g.count++;
            Thread.sleep(1000/g.fps); //inverse of refresh rate
            if(g.count > 5){
                throw new Exception();
            }
        }catch(Exception e){
            System.out.println("Game over");
            g.play = false;
        }
    }
}
项目:uni    文件:Flappy_CLI.java   
public static void main(String args[]){
    Game g = new Game(20,40,1);
    Input in = new Input();
    in.start();
    while(g.play){
        try{
            g.refresh();        
            if(in.getState() != Thread.State.WAITING){
                g.b.y--;
            }else{g.b.y++;}
            g.count++;
            Thread.sleep(1000/g.fps); //inverse of refresh rate
            if(g.count > 5){
                throw new Exception();
            }
        }catch(Exception e){
            System.out.println("Game over");
            g.play = false;
        }
    }
}
项目:ca-iris    文件:OSUtils.java   
/**
 * Spawn an OS subprocess.  Follows the Oracle-recommended method of
 * using ProcessBuilder rather than Runtime.exec(), and includes some
 * safeguards to prevent blocked and stale processes.  A thread is
 * created that will perform the spawn, consume its output and error
 * streams (to prevent blocking due to full buffers), then clean up.
 *
 * @param cmd The cmd/arg list for execution
 */
static public void spawnProcess(final List<String> cmd) {
    if (cmd == null)
        return;
    Thread t = new Thread() {
        public void run() {
            Process proc = null;
            proc = startProcess(cmd, true);
            if (proc != null) {
                consumeProcessOutput(proc);
                try {
                    proc.waitFor();
                }
                catch (InterruptedException e) {
                    // ignore (we terminate anyway)
                }
                destroyProcess(proc);
            }
            Thread.currentThread().interrupt();
        }
    };
    t.setDaemon(true);
    t.start();
}
项目:eagle    文件:FifoTaskScheduler.java   
public FifoTaskScheduler(int max, NodeMonitor nodeMonitor) {
  maxActiveTasks = max;
  activeTasks = 0;
  activeBigTasks = 0;
  activeBigTasksRequestId = new HashSet<String>();
  bigTaskReservations = 0;
  this.nodeMonitor = nodeMonitor;
  this.stealing = nodeMonitor.getStealing();

  new Thread(""){
      public void run(){
        while(true){
try{
    Thread.sleep(1000);
}catch(Exception e){}
LOG.info("Currently executing: "+activeTasks+" big: "+activeBigTasks+" queue: "+taskReservations.size()+ " big enqueued: "+ bigTaskReservations);
 }
      }
    }.start();

}
项目:hadoop-EAR    文件:Standby.java   
/**
 * Instantiates ingest thread for the current edits segment.
 */
private void instantiateIngest() throws IOException {
  InjectionHandler.processEvent(InjectionEvent.STANDBY_INSTANTIATE_INGEST);
  try {
    synchronized (ingestStateLock) {
      if (checkIngestState()) {
        LOG.info("Standby: Ingest for txid: " + currentSegmentTxId
            + " is already running");
        return;
      }
      assertState(StandbyIngestState.NOT_INGESTING);
      ingest = new Ingest(this, fsnamesys, confg, currentSegmentTxId);
      ingestThread = new Thread(ingest);
      ingestThread.setName("Ingest_for_" + currentSegmentTxId);
      ingestThread.start();
      currentIngestState = StandbyIngestState.INGESTING_EDITS;
    }
    LOG.info("Standby: Instatiated ingest for txid: " + currentSegmentTxId);
  } catch (IOException e) {
    setIngestFailures(ingestFailures + 1);
    currentIngestState = StandbyIngestState.NOT_INGESTING;
    throw e;
  }
}
项目:hadoop-EAR    文件:Standby.java   
/**
 * If checkpoint fails continuously, we want to abort the standby. We want to
 * avoid the situation in which the standby continuously rolls edit log on the
 * primary without finalizing checkpoint.
 */
private void handleCheckpointFailure() {
  setCheckpointFailures(checkpointFailures + 1);
  if (checkpointFailures > MAX_CHECKPOINT_FAILURES) {
    LOG.fatal("Standby: Checkpointing - standby failed to checkpoint in "
        + checkpointFailures + " attempts. Aborting");
  } else {
    // We want to give some time for some transition error to recover
    // and DNS caching to expire. This is mainly for small clusters
    // where checkpoint can be very fast. Doesn't hurt if we sleep
    // on large clusters too.
    //
    LOG.info("Sleeping " + CHECKPOINT_SLEEP_BEFORE_RETRY
        + " msecs before retry checkpoints...");
    try {
      Thread.sleep(CHECKPOINT_SLEEP_BEFORE_RETRY);
      return;
    } catch (InterruptedException ie) {
      LOG.warn("Standby: Checkpointing - Thread interrupted"
          + " while sleeping before a retry.", ie);
    }
  }
  FSEditLog.runtime.exit(-1);
}
项目:ImageQuiz    文件:TimerClass.java   
public void run(){

    timeExpired = true;
    mTime = mTime * 1000;
    double startTime = System.currentTimeMillis();
    double stopTime = startTime + mTime;
    while(System.currentTimeMillis() < stopTime && timeExpired == false){
          try {
            Thread.sleep(10);
        } catch (InterruptedException e){ }
    }

    timeExpired = true;


}
项目:VoltDB    文件:AsyncBenchmark.java   
/**
 * Connect to a single server with retry. Limited exponential backoff. No
 * timeout. This will run until the process is killed if it's not able to
 * connect.
 *
 * @param server
 *            hostname:port or just hostname (hostname can be ip).
 */
void connectToOneServerWithRetry(String server) {
    int sleep = 1000;
    while (runBenchmark) {
        try {
            client.createConnection(server);
            break;
        } catch (Exception e) {
            log.error(_F("Connection failed - retrying in %d second(s).\n",
                    sleep / 1000));
            try { Thread.sleep(sleep); }
            catch (Exception interruted) { }
            if (sleep < 8000)
                sleep += sleep;
        }
    }
    log.info(_F("Connected to VoltDB node at: %s.\n", server));
}
项目:VoltDB    文件:AsyncBenchmark.java   
/**
 * Connect to a set of servers in parallel. Each will retry until
 * connection. This call will block until all have connected.
 *
 * @param servers
 *            A comma separated list of servers using the hostname:port
 *            syntax (where :port is optional).
 * @throws InterruptedException
 *             if anything bad happens with the threads.
 */
void connect(String servers) throws InterruptedException {
    log.info("Connecting to VoltDB...");

    String[] serverArray = servers.split(",");
    final CountDownLatch connections = new CountDownLatch(
            serverArray.length);

    // use a new thread to connect to each server
    for (final String server : serverArray) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                connectToOneServerWithRetry(server);
                connections.countDown();
            }
        }).start();
    }
    // block until all have connected
    connections.await();
}
项目:populus    文件:CellController.java   
public CellController(CellFunction evaluator){
    setType(OutputTypes.kCell);
    setBackground(Color.black);
    this.setLayout(gbl1);
    cf = evaluator;
    cellPanel = new CellPanel(this,cf.initialF(),cf.getStrings(),cf.getDemarcations(), cf.getColorPalette());
    cellPanel.setBackground(Color.black);
    if(cf.getBreakInterval()==1) setPaused(true);
    try  {
        jbInit();
        addKeyListener(this);
    }
    catch(Exception e) {
        e.printStackTrace();
    }
    numRuns = evaluator.getGeneration();
    cellUpdater = new Thread(this);
    cellUpdater.start();
}
项目:petablox    文件:T.java   
public static void main(String[] args) {
    // thrd 1
    Thread thrd1 = new Thread() {
        public void run() {
            foo();
        }
    };
    thrd1.start();

    // thrd 2
    Thread thrd2 = new Thread() {
        public void run() {
            bar();
        }
    };
    thrd2.start();
}
项目:JAVA-Overview    文件:threadAndRunnable.java   
public static void main(String[] args)
   {

StringBuilder s = new StringBuilder("Hahaha");

// Notice: void run method are the same to both, but I overloaded it.
Thread t = new Thread(new threadAndRunnable(s)); // this calls void run method 
t.start();                                       // by the Interface Runnable

(new threadAndRunnable()).start(); // this calls a Thread by class Thread()

for(int i=0; i < 10; i++) // And it, only repetely shows a message 
       {
    System.out.println("tchau!");
    try{Thread.sleep(90);}catch(InterruptedException e){} 
       }

   }
项目:search    文件:RTimer.java   
/*************** Testing *******/
public static void main(String []argv) throws InterruptedException {
  RTimer rt = new RTimer(), subt, st;
  Thread.sleep(100);

  subt = rt.sub("sub1");
  Thread.sleep(50);
  st = subt.sub("sub1.1");
  st.resume();
  Thread.sleep(10);
  st.pause();
  Thread.sleep(50);
  st.resume();
  Thread.sleep(10);
  st.pause();
  subt.stop();
  rt.stop();

  System.out.println( rt.toString());
}
项目:texasholdem-engine    文件:TexasHoldem.java   
@Override
// close the bot processes, save, exit program
public void finish() throws Exception
{
    for(Player player : players) {
        player.getBot().finish();
    }
    Thread.sleep(100);

    // write everything
    try { 
        this.saveGame(); 
    } catch(Exception e) {
        e.printStackTrace();
    }

    System.out.println("Done.");

       System.exit(0);
}
项目:warlight2-engine    文件:Warlight2.java   
/**
 * close the bot processes, save, exit program
 */
@Override
public void finish() throws Exception
{
    this.player1.getBot().finish();
    this.player2.getBot().finish();
    Thread.sleep(100);

    // write everything
    try { 
        this.saveGame(); 
    } catch(Exception e) {
        e.printStackTrace();
    }

    System.out.println("Done.");

       System.exit(0);
}
项目:infobip-open-jdk-8    文件:DisplayChangeVITest.java   
public static void main(String[] args) throws Exception {
    DisplayChangeVITest test = new DisplayChangeVITest();
    GraphicsDevice gd =
        GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice();
    if (gd.isFullScreenSupported()) {
        gd.setFullScreenWindow(test);
        Thread t = new Thread(test);
        t.run();
        synchronized (lock) {
            while (!done) {
                try {
                    lock.wait(50);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
        }
        System.err.println("Test Passed.");
    } else {
        System.err.println("Full screen not supported. Test passed.");
    }
}
项目:jdk8u-dev-jdk    文件:DisplayChangeVITest.java   
public static void main(String[] args) throws Exception {
    DisplayChangeVITest test = new DisplayChangeVITest();
    GraphicsDevice gd =
        GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice();
    if (gd.isFullScreenSupported()) {
        gd.setFullScreenWindow(test);
        Thread t = new Thread(test);
        t.run();
        synchronized (lock) {
            while (!done) {
                try {
                    lock.wait(50);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
        }
        System.err.println("Test Passed.");
    } else {
        System.err.println("Full screen not supported. Test passed.");
    }
}
项目:frinika    文件:PJVoiceServer.java   
public void startAudioOutput()
{

    try {
           lineOut = (SourceDataLine)AudioSystem.getMixer(currentMixer).getLine(infoOut);
           if(standardLatency)
               lineOut.open(format,bufferSize);
           else
               lineOut.open(format);

           lineOut.start();
           System.out.println("Buffersize: "+bufferSize+" / "+lineOut.getBufferSize());
       } catch (Exception e) {
           lineOut = null;
           System.out.println("No audio output available. Use Audio Devices dialog to reconfigure.");
       }

    Thread thread = new Thread(this);
    // thread.setPriority(Thread.MAX_PRIORITY);
    thread.start();
}
项目:HentaiAtHome-Mirror    文件:HTTPResponseProcessorProxy.java   
public byte[] getBytesRange(int len) throws Exception {
    // wait for data
    int endoff = readoff + len;

    //Out.debug("Reading data with readoff=" + readoff + " len=" + len + " writeoff=" + writeoff);

    int timeout = 0;

    while(endoff > gdf.getCurrentWriteoff()) {
        try {
            Thread.currentThread().sleep(10);
        } catch(Exception e) {}

        if( ++timeout > 30000 ) {
            // we have waited about five minutes, probably won't happen
            Out.info("Timeout while waiting for proxy request.");
            throw new Exception("Timeout while waiting for proxy request.");
        }
    }

    byte[] range = gdf.getDownloadBufferRange(readoff, endoff);
    readoff += len;
    return range;
}
项目:HentaiAtHome-Mirror    文件:GalleryDownloadManager.java   
public GalleryDownloadManager(HentaiAtHomeClient client) {
    this.client = client;       
    processedHHDLFiles = new ArrayList<File>();
    pendingGalleries = new ArrayList<Gallery>();
    lastTokenRequest = System.currentTimeMillis() + 3600060;    // we wait until one hour after client start before we start requesting tokens, so the server has time to qualify the client. there's no point reducing this, as it's checked server-side.

    try {
        hhdldir = FileTools.checkAndCreateDir(new File("hathdl"));
        downloadeddir = FileTools.checkAndCreateDir(new File("downloaded"));
    } catch(java.io.IOException e) {
        HentaiAtHomeClient.dieWithError(e);
    }

    myThread = new Thread(this);
    myThread.start();
}
项目:PADListener    文件:Spider.java   
public void run() {
    _model.setStatus("Started");
    _model.setStopping(false);
    _runThread = Thread.currentThread();

    _model.setRunning(true);
    while (!_model.isStopping()) {
        // queue them as fast as they come, sleep a bit otherwise
        if (!queueRequests()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ie) {}
        } else {
            Thread.yield();
        }
    }
    _fetcherQueue.clearRequestQueue();
    _model.setRunning(false);
    _runThread = null;
    _model.setStatus("Stopped");
}
项目:PADListener    文件:Listener.java   
public boolean stop() {
    _stop = true;
    try {
        _serversocket.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (!_stopped) {
        for (int i=0; i<20; i++) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ie) {}
            if (_stopped) {
                return true;
            }
        }
        return false;
    } else {
        return true;
    }
}