关于管道和过滤器实施的一些问题

发布于 2024-10-05 08:22:59 字数 571 浏览 3 评论 0原文

我将开发一个名为 ExtractInfoFromUrl 的组件。该组件有一个名为 addUrl(url) 的方法,该方法接受 url 并打开给定的 url 并从相应页面提取信息,完成后引发一个事件。该组件内部由管道和过滤器组成。

我有 3 个问题:

  1. 我想知道什么会更好——让每个 Filter 都有一个 Thread(也就是说,在 Java 中,继承自Thread) 或让 PipeThreads

  2. 很明显,我的过滤器或管道必须带有螺纹。但是我是否也必须为我的组件本身使用线程?我需要一个控制其他线程的线程,并且我相信主程序的线程不适合该任务,但我不太确定为什么。

  3. 是否有任何其他类型的 PipedReaders/Writers Java 实现允许我处理其他类型的数据而不是 char/int ?我想说,这对我来说有点太低了。例如,如果有其他允许使用字符串的方法,那就更好了。

谢谢

I am going to develop a component called ExtractInfoFromUrl. This component has a method called addUrl(url) that accepts urls and will open the given url and extract info from the corresponding page, raising an event when done. Internally, the component is composed of pipes and filters.

I have 3 questions:

  1. I'd like to know what would be better -- to have each Filter have a Thread(that is, in Java, inherit from Thread) or have the Pipes have Threads?

  2. It is obvious that I will have to have my filters or my pipes with threads. But won't I have, too, to use a Thread for my component itself? I need a thread that controls the other ones, and I believe the main program's thread is not suited for the task, but I am not too sure why.

  3. Is there any other kind of Java implementation for PipedReaders/Writers that allows me to handle other kinds of data instead of char/int ? That is a bit too low level for me, I'd say. If there were some other that'd allow strings instead, for example, it'd be preferable.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

还不是爱你 2024-10-12 08:22:59
  1. 一方面,通常最好实现 Runnable 而不是扩展 Thread,但无论如何,我不认为您希望让过滤器或管道扩展 Thread 或实现 Runnable,而是让每个管道都用于一个新的线程。

  2. “组件”是什么意思?你的意思是可视化GUI组件吗?或者不同的东西?

  3. 我已将 PipedWriter 包装在 PrintWriter 中

  1. For one, it's usually preferable to implement Runnable rather than extend Thread, but regardless, I don't think that you'll want to have your Filters or Pipes extend Thread or implement Runnable, but rather have each pipe be used in a new Thread.

  2. What do you mean by "component"? Do you mean a visualized GUI component? Or something different?

  3. I've wrapped PipedWriters in PrintWriter

放赐 2024-10-12 08:22:59

从概念上讲,过滤器代表过滤器和管道架构中的计算,因此我认为线程与过滤器关联更有意义(如果完全使用线程)。管道是模式的“通信”部分。

同样,从概念上讲,如果从检索到的页面中提取的信息不依赖于任何其他数据,则仅在多处理器情况下为它们使用线程才有意义。我也不确定为什么需要主线程 - 也许你可以详细说明。

为什么不考虑消息队列而不是使用低级读取器/写入器呢?

Conceptually, filters represent the computations in a filter-and-pipe architecture, so I would think it makes more sense for the threads to be associated with filters (if threads are used at all). Pipes are the "communication" portion of the pattern.

Again, conceptually, if the information extracted from a retrieved page does not depend on any other data, then using threads for them makes sense only in a multiprocessor case. I'm also not sure why there is a need for a master thread - perhaps you can elaborate.

Instead of using low-level Reader/Writers, why not consider message queues?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文