简体   繁体   English

Java连接线程池和connectionfactory?

[英]Java connection thread pool AND connectionfactory?

I think somebody is confusing their patterns. 我认为有人在混淆他们的模式。 I've got one guy telling me to use thread pooling and another telling me to use a ConnectionFactory (granted the second guy is not a software engineer, but a very knowledgeable system architect). 我有一个人告诉我使用线程池,另一个人告诉我使用ConnectionFactory(当然,第二个人不是软件工程师,而是知识渊博的系统架构师)。 I'm going to use thread pooling, so we can keep the number of connections to a reasonable number of threads. 我将使用线程池,因此我们可以将连接数保持在合理数量的线程中。 I've looked all over the internet and I cannot see anywhere where anyone is using both together. 我看了遍整个互联网,却看不到任何人同时使用两者的地方。 I'm thinking about dumping the ConnectionFactory, because it seems redundant at the very least and I just cannot see why or how to use both. 我正在考虑转储ConnectionFactory,因为它看起来至少是多余的,而且我看不出为什么或如何同时使用两者。

Just curious to see if somebody more knowledgeable than me has ever seen the two used together and can enlighten me as to why. 只是想知道是否有人比我知识渊博,曾经见过两者一起使用,并且可以启发我为什么。

Also, each connection has to have its own instance of several other classes and we are using a pub-sub architecture. 另外,每个连接都必须具有自己的其他几个类的实例,并且我们使用的是pub-sub体系结构。 I need to make sure that the subscribers are NOT getting a published message that belongs to another connection. 我需要确保订户没有收到属于另一个连接的已发布消息。 Can I manage that with a ConnectionFactory or do I absolutely need to use a new thread to ensure separation between connection processes? 我可以使用ConnectionFactory进行管理,还是绝对需要使用新线程来确保连接过程之间的分离?

Just looking for some direction here. 只是在这里寻找方向。

Thank you. 谢谢。

In general Factory pattern is how to create an object. 一般来说, 工厂模式是如何创建对象的。 So ConnectionFactory pattern abstracts the way Conncetion is created. 因此, ConnectionFactory模式抽象了创建Conncetion的方式。

Thread pool abstracts the way threads are managed, ie the main things are: when they are started, how many of threads are runnable, their scheduling, their stopping - not creation process! 线程池抽象了线程的管理方式,即主要内容:启动线程时,有多少个线程可运行,它们的调度,它们的停止-而不是创建过程!

You can use both this patterns. 您可以同时使用这两种模式。 Your pool can use factory to properly create thread or connection objects. 您的可以使用工厂来正确创建线程或连接对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM