在托管环境中使用非托管线程有哪些缺点?
在 weblogic 应用程序服务器等托管环境中创建自己的线程有哪些缺点?
每当我在应用程序服务器内工作时,我总是使用托管线程(使用 WorkManager api)。
但是,我不清楚在应用程序服务器内使用非托管线程可能导致的缺点或问题。
What are the disadvantages of creating my own threads inside a managed environment like a weblogic application server?
I have always used managed threads (using the WorkManager api) whenever i am working inside an application server.
However I am unclear on the disadvantages or issues that might be caused by using non-managed threads inside the app server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只是失去了托管线程的好处。
托管线程使您能够从具有最大和最小大小、增量速率的“池”中分配线程,并且能够在负载较重时对每个池的请求进行排队。您还可以受益于能够监视这些线程并在运行时控制它们的行为(例如从 Weblogic 控制台)。
You just lose the benefits of having managed threads.
Managed threads give you the ability to allocate threads from "pools" with maximal and minimal size, an increment rate, and the ability to queue requests for each pool if it is under heavy load. you also have the benefit of being able to monitor these threads and control their behavior in run-time (e.g. from the Weblogic console).
当您在线程中运行少量代码并且它不等待其他线程(没有大量使用锁等)时,使用线程池没有问题。
但是当你的线程需要长时间运行大量代码(例如,等待锁,等待特定资源)时,使用线程池等并不是一个好的做法。
另一个问题是,当你使用运行程序主要逻辑的线程池,您可能会陷入困境,等待其他线程完成。这是您应该管理自己的线程的另一种做法。
When you run small amount of code in the thraed, and it's not waiting for other thread (not a vast use in locks etc.) there is no problem using the thread pool.
but when your thread needs to run a large amount of code, for long period (for example, waiting on locks, waiting for specific resources), it's not a good practice to use the thread pool etc.
Another problem is that when you use the pool for threads that run the main logic of the program, you might get stuck, waiting for other threads to finish. that's another practice where you should manage you're own threads.