本帖最后由 sunli880127 于 2013-11-28 10:54:12 编辑

解决方案 »

  1.   

    这是定时任务,就是定期执行的。
    而且,你这里就一个new Cat()线程吧?ThreadPoolExecutor应该能满足你多线程的实验。
      

  2.   

    原谅我使用中文的DOC
    scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) 
    创建并执行一个在给定初始延迟后首次启用的定期操作,后续操作具有给定的周期;也就是将在 initialDelay 后开始执行,然后在 initialDelay+period 后执行,接着在 initialDelay + 2 * period 后执行,依此类推。
    看到了吧?就应该是每两秒执行一次,不知你有何高见?
      

  3.   

    ScheduledFuture<?> scheduleAtFixedRate(Runnable command,
                                         long initialDelay,
                                         long period,
                                         TimeUnit unit)Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is executions will commence after initialDelay then initialDelay+period, then initialDelay + 2 * period, and so on. If any execution of the task encounters an exception, subsequent executions are suppressed. Otherwise, the task will only terminate via cancellation or termination of the executor. If any execution of this task takes longer than its period, then subsequent executions may start late, but will not concurrently execute.
      

  4.   

    I LOVE YOU
    看中文DOC是我最大的错
      

  5.   

    这个线程池框架的作用是每2秒启动一个这样的线程,不止一个的
    new 操作只有一次,定期执行,都是同一个线程的执行。LZ可以跟代码看看,或者反过来想想:我自己随便new了一个Runnable的实现类,定时任务管理器怎么知道我的内部构造,如何再new一个新的呢?
      

  6.   

    I LOVE YOU
    看中文DOC是我最大的错
    scheduleAtFixedRate
    ScheduledFuture<?> scheduleAtFixedRate(Runnable command,
                                           long initialDelay,
                                           long period,
                                           TimeUnit unit)创建并执行一个在给定初始延迟后首次启用的定期操作,后续操作具有给定的周期;也就是将在 initialDelay 后开始执行,然后在 initialDelay+period 后执行,接着在 initialDelay + 2 * period 后执行,依此类推。如果任务的任何一个执行遇到异常,则后续执行都会被取消。否则,只能通过执行程序的取消或终止方法来终止该任务。如果此任务的任何一个执行要花费比其周期更长的时间,则将推迟后续执行,但不会同时执行。
      

  7.   

    I LOVE YOU
    看中文DOC是我最大的错
    scheduleAtFixedRate
    ScheduledFuture<?> scheduleAtFixedRate(Runnable command,
                                           long initialDelay,
                                           long period,
                                           TimeUnit unit)创建并执行一个在给定初始延迟后首次启用的定期操作,后续操作具有给定的周期;也就是将在 initialDelay 后开始执行,然后在 initialDelay+period 后执行,接着在 initialDelay + 2 * period 后执行,依此类推。如果任务的任何一个执行遇到异常,则后续执行都会被取消。否则,只能通过执行程序的取消或终止方法来终止该任务。如果此任务的任何一个执行要花费比其周期更长的时间,则将推迟后续执行,但不会同时执行。
    好吧,看来是我看的不仔细,因为没看下面的详情