相关疑难解决方法(0)

为什么ThreadGroup受到批评?

我知道当前使用Executors而不是ThreadGroup的做法:

  • 通常首选的方式来处理线程
  • 从线程中捕获异常等...

然而,ThreadGroup本身的固有缺陷是什么(我听过那个类的含糊不清的批评)?

谢谢你的回答.

PS.似乎没有回答这个问题.

java concurrency multithreading thread-safety

25
推荐指数
1
解决办法
9250
查看次数

Java多线程 - 线程优先级

任何人都可以解释线程优先级如何在java中工作.这里的困惑是,如果java不保证Thread根据其优先级的实现,那么为什么这个setpriority()函数用于.

我的代码如下:

public class ThreadSynchronization implements Runnable{

    public synchronized void run() {
        System.out.println("Starting Implementation of Thread "+Thread.currentThread().getName());
        for(int i=0;i<10;i++)
        {
            System.out.println("Thread "+Thread.currentThread().getName()+" value : "+i);
        }
        System.out.println("Ending Implementation of Thread "+Thread.currentThread().getName());
    }

    public static void main(String[] args) {
        System.out.println("Program starts...");
        ThreadSynchronization th1 = new ThreadSynchronization();
        Thread t1 = new Thread(th1);
        t1.setPriority(1);
        synchronized(t1)
        {
            t1.start();
        }

        ThreadSynchronization th2 = new ThreadSynchronization();
        Thread t2 = new Thread(th2);
        t2.setPriority(9);
        synchronized (t2) {
            t2.start(); 
        }

        System.out.println("Program ends...");
    }
}
Run Code Online (Sandbox Code Playgroud)

在上面的程序中,即使我改变优先级,我发现输出没有区别.另外,如何使用线程优先级的实时应用将会有很大帮助.谢谢.

java multithreading thread-priority

11
推荐指数
2
解决办法
7632
查看次数