Thread.yield();你这样又是新的thread,直接yield()就行了。

解决方案 »

  1.   

    yield()表示当前线程(running)愿意放弃cpu,回到runnable状态,但不保证别的线程会得到cpu
    jvm在运行时有可能会忽略yield()
    即使执行了yield(),当前线程变成可运行状态,但这时它还是会去和别的线程抢cpu
    这和优先级没有关系,但优先级相差越大,高优先级的线程越有可能得到cpu可以看一下这个http://freish.iteye.com/blog/1477715
    java7的文档注释:    /**
         * A hint to the scheduler that the current thread is willing to yield
         * its current use of a processor. The scheduler is free to ignore this
         * hint.
         *
         * <p> Yield is a heuristic attempt to improve relative progression
         * between threads that would otherwise over-utilise a CPU. Its use
         * should be combined with detailed profiling and benching to
         * ensure that it actually has the desired effect.
         *
         * <p> It is rarely appropriate to use this method. It may be useful
         * for debugging or testing purposes, where it may help to reproduce
         * bugs due to race conditions. It may also be useful when designing
         * concurrency control constructs such as the ones in the
         * {@link java.util.concurrent.locks} package.
         */
        public static native void yield();
      

  2.   

    本来就是静态方法,yield()和Thread.yield()是一样的
      

  3.   

    本来就是静态方法,yield()和Thread.yield()是一样的你确定?对象不一样,是不是静态方法有啥关系?
      

  4.   

    本来就是静态方法,yield()和Thread.yield()是一样的你确定?对象不一样,是不是静态方法有啥关系?静态方法跟对象本来就没关系,更何况静态方法本来就应该用ClassName.method()的方式调用,obj.method()反而还会带来歧义,大概会收到编译器警告的吧
      

  5.   

     yield是 当前正在执行线程让出执行权,让别的线程执行,,,,lz理解有误啊
      

  6.   

    不是让别的线程执行   是让出CPU  让所有线程去抢CPU  当然刚刚放弃的线程也是可以抢到的吧
      

  7.   

    不是让别的线程执行   是让出CPU  让所有线程去抢CPU  当然刚刚放弃的线程也是可以抢到的吧恩 对
      

  8.   

    那么yield是不影响代码的执行么???
      

  9.   

    那么yield是不影响代码的执行么???没有看懂你的意思。。