【发布时间】:2012-04-30 01:25:27
【问题描述】:
我在Java中有这种情况:
在名为 I 的内部模块上。 一个大模块 Z,通过 DBus 从 I 接收消息。 这个大模块 Z 与外部服务器 E 通信(对于 Dbus 收到的每条消息)。
通过 DBus 架构,每完成一个请求,在 Z 模块中都会创建一个新的线程来处理它。
与 E 交流的最佳方法是什么?
a) Make a class with a method SendToExternalServer(). this method will be called every time that have a new DBus message.
i) The method has only one HttpUrlConnection.
ii) The method create a differente HttpUrlConnection instance every time is called.
b) Same situation on a) but now the method SendToExternalServer() is static
i) (same situations)
ii) (same situations)
c) Same situation on a) but the class extends the interface Runnable
i) (same situation)
ii) (same situation)
d) OTHER ?
提前致谢 若昂
【问题讨论】:
-
我不会为每个传入的事件创建一个新线程。而是使用一个使用线程池的事件调度程序(如 user949300 建议的执行程序)。
标签: java multithreading httprequest dbus