Java编程语言中的线程 [英] Threads In Java Programming Language

查看:72
本文介绍了Java编程语言中的线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好。



我想问你一个问题。在线程中使用线程是不好的做法吗?类似于:



Hello.

I would like to ask you a question. Is it bad practice to use threads in thread? Something like:

 Thread bigThread=new Thread(){
     public void run(){

        //do something here
        PersonalThread pThread=new PersonalThread(); //class wich extends Thread class, and implements run() method
        pThread.start();
        try{
        pThread.join();
        }catch(InterruptedException e){

        }

     }


}
bigThread.start();





感谢您的评论或回复。



Thank you for comment or response.

推荐答案

原则上,从其他线程启动线程没有问题。线程之间没有父子关系!将线程调用到另一个线程中没有什么大的优势!

最重要的是你可能会遇到创建更多线程会产生争用的问题(由于上下文切换开销和锁定)事情进展缓慢。
In principle there is no issue with starting threads from other threads. There''s no parent child relation between Threads! There''s no big advantage calling a thread inside another!
The most important thing is that you might run into the point where creating more threads creates contention (due to context switching overhead and perhaps locking) making things slow.


这篇关于Java编程语言中的线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆