在主线程中使用 TAdsSettings 对象和在其他线程中使用 AdsQuery 对象是否安全?

发布于 2024-07-05 18:03:50 字数 288 浏览 12 评论 0原文

我有一个 Win-CGI 应用程序,目前正在转换为 ISAPI。

该应用程序使用 Extended Systems Advantage 数据库服务器的 TDataset 后代。

由于 TAdsSettings 对象只能有一个实例,因此必须是 在主线程中。

请求线程中需要 TAdsQuery 对象。

这会起作用吗?也就是说,请求线程中的 AdsQueries 会起作用吗? 从主程序中的 AdsSettings 对象中获取全局设置 线程,这会是线程安全的吗?

I have a Win-CGI application I am currently converting to ISAPI.

The application uses the TDataset descendants for Extended Systems Advantage Database Server.

As there can be only one instance of a TAdsSettings object, this must be
in the main thread.

TAdsQuery objects are needed in the request threads.

Will this work - that is, will the AdsQueries in the request threads
pick up the global settings from the AdsSettings object in the main
thread, and will this be thread safe?

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

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

发布评论

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

评论(3

划一舟意中人 2024-07-12 18:03:50

是的,它会起作用。 TAdsSettings 组件修改 Advantage Client Engine (ACE) 中的设置,并且通过 ISAPI,将加载所有线程使用的一个 ACE 实例。

不过,我不会推荐它。 根据您要更改的设置,直接调用 ACE API 会更有意义。 例如,如果您仅设置日期格式,则消除 TAdsSettings 组件并仅调用采用连接句柄的 AdsSetDateFormat60 更有意义。 摆脱 TAdsSettings 组件可以消除设置 ACE 全局设置的大量调用。 其中许多调用必须有一个同步对象,以在全局更改时保持所有连接关闭。 这会对性能产生负面影响,尤其是在 Web 应用程序等多线程应用程序中。 而是进行对指定连接句柄进行操作的调用。

您可以通过引用 TAdsConnection.Handle 属性或调用 TAdsQuery.GetAceConnectionHandle 方法来获取连接句柄。

Yes, it will work. The TAdsSettings component modifies settings in the Advantage Client Engine (ACE), and with ISAPI there will be one instance of ACE loaded that all threads use.

I wouldn't recommend it, however. Depending on the settings you are changing it would make more sense to just call the ACE APIs directly. For example, if you are only setting the date format, it makes more sense to eliminate the TAdsSettings component and just call AdsSetDateFormat60, which takes a connection handle. Getting rid of the TAdsSettings component eliminates lots of calls to set ACE global settings. Many of those calls have to have a sync object to hold all connections off while the global is changed. That will have a negative performance impact, especially in a multi-threaded application like a web application. Instead make calls that operate on the specified connection handle.

You can get the connection handle by referencing the TAdsConnection.Handle property or calling the TAdsQuery.GetAceConnectionHandle method.

秋意浓 2024-07-12 18:03:50

如果 AdsQueries 不在主线程中(即 System.MainThreadID <>),请确保 AdsQueries 使用 Synchronize 直接访问 TAdsSettings(或使用消息系统在工作线程和主线程之间进行通信,而不是直接访问)。 Windows.GetCurrentThreadID)

Make sure the AdsQueries use Synchronize to access the TAdsSettings directly (or use a messaging system to comunicate between worker threads and main thread instead of accessing directly) if they are not in the main thread (i.e. System.MainThreadID <> Windows.GetCurrentThreadID)

温馨耳语 2024-07-12 18:03:50

我还在新闻组中提出了这个问题:devzone.advantagedatabase.com,Advantage.Delphi

为了完整起见,我将添加该线程其余部分的进一步问题/答案:

问题(我):

线程中的许多查询当前未附加到
TAdsConnection 对象。 我计划为每个创建一个连接
供这些“孤立”查询使用的线程,但它是一个大型应用程序
这需要时间。 我也很确定唯一的非默认
TAdsSettings 对象中的属性是服务器类型集,可以
也可以在连接组件中设置,因此一旦所有查询都完成
链接到连接,将不需要设置组件。 我会看看
直接调用设置 API 作为替代方案。

与此同时,我确实有一个关于线程和查询的问题
没有分配连接组件。 我从帮助文件中注意到
如果多个线程中的查询共享单个连接对象,则
查询将串行运行而不是同时运行。 与一个
每个线程中的连接对象,这不应该是问题,但我是
想知道没有连接对象的查询
分配的。 他们是否会被视为独立连接
多线程并发的观点,还是会
被认为是在同一个连接上,因此必须屈服于每个
其他?

答案(杰里米):

您需要解决这个问题。 他们只会搜索全局连接列表
找到具有相同路径的一个,他们将使用该连接。 不好
在多线程应用程序中。

因此,从 Jeremy 的回答来看,最好为每个线程创建至少一个 TAdsConnection 对象,并确保所有查询都附加到它,否则可能会发生序列化。

I also had asked this question in the newsgroup: devzone.advantagedatabase.com, Advantage.Delphi

For the sake of completeness, I'll add further question/answer from the rest of that thread:

Question (Me):

Many of the queries in threads are currently not attached to a
TAdsConnection object. I'm planning to create a connection for each
thread for these "orphan" queries to use, but it is a large application
and this will take time. I'm also pretty sure that the only non-default
property in the TAdsSettings object is the server-types set, which can
also be set in the connection component, thus once all queries are
linked to connections, the settings component wont be needed. I'll look
into calling the settings API directly as an alternative.

In the meantime, I do have a question about threading and the queries
with no connection component assigned. I noted from the help files that
if queries in multiple threads share a single connection object, the
queries will be run in series rather than concurrently. With a
connection object in each thread, this should not be an issue, but I am
wondering about the queries which do not have a connection object
assigned. Will they be considered to be on independent connections from
the point of view of multithreading concurrency, or will they be
considered to be on the same connection and thus have to yield to each
other?

Answer (Jeremy):

You will need to address this. They will just search a global list of connections
to find one with the same path, and they will use that connection. Not good
in a multi-threaded application.

Thus, from Jeremy's answer it is best to create at least one TAdsConnection object for each thread and ensure that all queries are attached to it, otherwise serialization may occur.

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