Xml-Rpc + Mysql.NET =线程问题 [英] Xml-Rpc + Mysql.NET = Threading problem

查看:63
本文介绍了Xml-Rpc + Mysql.NET =线程问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我的项目使用Xml- Rpc接收消息,所以每次调用都来自不同的
线程。

来电正在MysqlConnection上执行SQL。

MysqlConnection没有比如当有人打电话追加时。


对于一个快速而肮脏的解决方案,我已经在收到的消息上放了一个Monitor()。

但是我想要最后得到了一个更好的解决方案。


你对我应该做的架构怎么看?


我应该创建和管理一个池MysqlConnection并且仅在游泳池

被完全锁定时锁定?


你知道已经为这种情况制作了解决方案吗?


非常感谢您的评论和想法,

cyrille。


PS:在我放置丑陋的显示器之前,我遇到了一些错误,如:


例外:连接必须有效和开放。 StackTrace:

at MySql.Data.MySqlClient.MySqlCommand.CheckState()

at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)

at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader()


异常:预期的预准备语句标记。 StackTrace:

at MySql.Data.MySqlClient.NativeDriver.Prepare(String sql,String [] parmNames)

at MySql.Data.MySqlClient.MySqlCommand.Prepare()

解决方案

显示器出了什么问题?


无论如何,这是非常典型的建议有一个连接池(

池)作为正确同步的访问并返回

需求的私有连接。

实际上是SqlConnection (对于SqlServer),它是为你做的。


否则你可以为每个传入的消息打开一个新的连接..


你不应该做的一件事是在

不同的帖子中同时使用相同的连接。


"#Cyrille37#" < CY ******* @ free.fr>在留言中写道

news:up ************** @ TK2MSFTNGP11.phx.gbl ...

大家好,

我来找你帮助管理多线程和数据库连接。

我的项目使用Xml-Rpc接收消息,所以每次调用都来自<不同的线程。
传入的调用正在MysqlConnection上执行SQL。
当concurents调用追加时,MysqlConnection不喜欢。

对于一个快速而肮脏的解决方案,我''我把一个Monitor()放到了收到的消息上。
但是我想最终得到一个更好的解决方案。

你对我应该做的架构怎么看?

你知道已经为这个案例制定了解决方案吗?

非常感谢您的评论和想法,
cyrille。

PS:在我放置丑陋的显示器之前,我遇到了一些错误:

E xception:连接必须有效且打开。 StackTrace:
MySql.Data.MySqlClient.MySqlCommand.CheckState()
MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior
行为)
at MySql.Data.MySqlClient .MySqlCommand.ExecuteReader()

异常:预期的预准备语句标记。 StackTrace:
MySql.Data.MySqlClient.NativeDriver.Prepare(String sql,String []
parmNames)
at MySql.Data.MySqlClient.MySqlCommand.Prepare()



你好Lloyd,

Lloyd Dupontaécrit:

监视器出了什么问题?


我对传入的消息进行多线程处理。

无论如何,这是非常典型的,并建议有一个连接池(
pool)作为一个正确同步的访问并返回一个私有连接请求。
实际上SqlConnection(对于SqlServer),它是为你做的。


那太好了。

我要为MySqlConnection找到或写一个连接池...

也许有人已经完成了它?

否则你可以为每个传入的消息打开一个新的连接..


我认为它会很重。

你不应该做的一件事就是在不同的线程中同时使用相同的连接。


感谢您的建议。我会小心的; o)


非常感谢你的议会。

问候,

cyrille。

"#Cyrille37#" < CY ******* @ free.fr>在消息中写道
新闻:up ************** @ TK2MSFTNGP11.phx.gbl ...

大家好,

我的项目使用Xml-Rpc接收消息,所以每次调用来自不同的
调用。
调用正在MysqlConnection上执行SQL。
当concurents调用追加时,MysqlConnection不喜欢。

对于一个快速而肮脏的解决方案,我放了一个监视器()收到的消息。
但我想最终得到一个更好的解决方案。

你对我应该做的架构怎么看?

我应该创建和管理一个MysqlConnection池,只在完全占用游泳池时才锁定?

你知道已经为这个案子做过解决方案了吗?

非常感谢你的评论和想法,
cyrille。

PS:在我放置丑陋的显示器之前,我遇到了一些错误:

Ex ception:连接必须有效且开放。 StackTrace:
MySql.Data.MySqlClient.MySqlCommand.CheckState()
MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior
行为)
at MySql.Data.MySqlClient .MySqlCommand.ExecuteReader()

异常:预期的预准备语句标记。 StackTrace:
MySql.Data.MySqlClient.NativeDriver.Prepare(String sql,String []
parmNames)
at MySql.Data.MySqlClient.MySqlCommand.Prepare()






Lloyd Dupontaécrit:

Hi Cyrille37

监视器出了什么问题?我对传入的消息进行了多线程处理。


错误....你能改写这句话吗?
我无法猜出它的含义......




抱歉我的英语不好。我使用额外的球再试一次:


使用Monitor()收到消息时,我失去了多线程的优势。


这是否更具可读性?

; o)

我有类似的东西(作为这个答案的附件)。
这是一个无用的和平作为SqlConnection的代码已经在引擎盖下使用了
连接池。
但是如果你用MySqlConnection替换所有的SqlConnection东西,它会突然开始变得有意义!




感谢很多!!!


好​​的,我会在今天下午尝试一下。


< ;; oP>我希望你制作一个非错误的代码< /; oP>


我在测试后给你一个报告...


干杯,

cyrille


Hello all,

I come to you to getting help for managing multi threading and database connection.

My project use Xml-Rpc to receive messages, so each call come from a different
thread.
Incoming calls are executing SQL on a MysqlConnection.
MysqlConnection does not like when concurents calls appends.

For a fast and dirty solution, I''ve put a Monitor() at messages arrived.
But I would like to finally got a nicer solution.

What do you think about the architecture I should make ?

Should I create and manage a Pool of MysqlConnection and only locking when pool
is fully occuped ?

Do you know already made solutions for that case ?

Thanks a lot for you comments and ideas,
cyrille.

PS: Before I put the ugly Monitor, I got some errors like :

Exception: Connection must be valid and open. StackTrace:
at MySql.Data.MySqlClient.MySqlCommand.CheckState()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader( CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader( )

Exception: Expected prepared statement marker. StackTrace:
at MySql.Data.MySqlClient.NativeDriver.Prepare(String sql, String[] parmNames)
at MySql.Data.MySqlClient.MySqlCommand.Prepare()

解决方案

what''s wrong with the Monitor?

Anyway it''s very typical and advised to have a connection pool which (the
pool) as a properly synchronized access and return a private connection on
demand.
In fact SqlConnection (for SqlServer), does it for you under the hood.

Otherwise you could open a new connection for each incoming message..

One thing you should NOT do is use the same connection at the same time in
different thread.

"# Cyrille37 #" <cy*******@free.fr> wrote in message
news:up**************@TK2MSFTNGP11.phx.gbl...

Hello all,

I come to you to getting help for managing multi threading and database
connection.

My project use Xml-Rpc to receive messages, so each call come from a
different thread.
Incoming calls are executing SQL on a MysqlConnection.
MysqlConnection does not like when concurents calls appends.

For a fast and dirty solution, I''ve put a Monitor() at messages arrived.
But I would like to finally got a nicer solution.

What do you think about the architecture I should make ?

Should I create and manage a Pool of MysqlConnection and only locking when
pool is fully occuped ?

Do you know already made solutions for that case ?

Thanks a lot for you comments and ideas,
cyrille.

PS: Before I put the ugly Monitor, I got some errors like :

Exception: Connection must be valid and open. StackTrace:
at MySql.Data.MySqlClient.MySqlCommand.CheckState()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader( CommandBehavior
behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader( )

Exception: Expected prepared statement marker. StackTrace:
at MySql.Data.MySqlClient.NativeDriver.Prepare(String sql, String[]
parmNames)
at MySql.Data.MySqlClient.MySqlCommand.Prepare()



Hi Lloyd,

Lloyd Dupont a écrit :

what''s wrong with the Monitor?
I loos multi-threading processing of incoming messages.
Anyway it''s very typical and advised to have a connection pool which (the
pool) as a properly synchronized access and return a private connectionon
demand.
In fact SqlConnection (for SqlServer), does it for you under the hood.
That''s Great.
I''ve to find or write a connections pool for MySqlConnection ...
Perhaps someone already done it ?
Otherwise you could open a new connection for each incoming message..
I think it will be to heavy.
One thing you should NOT do is use the same connection at the same timein
different thread.
Thanks for your advise. I''ll be care ;o)

Thanks a lot for your councils.
Regards,
cyrille.

"# Cyrille37 #" <cy*******@free.fr> wrote in message
news:up**************@TK2MSFTNGP11.phx.gbl...

Hello all,

I come to you to getting help for managing multi threading and database
connection.

My project use Xml-Rpc to receive messages, so each call come from a
different thread.
Incoming calls are executing SQL on a MysqlConnection.
MysqlConnection does not like when concurents calls appends.

For a fast and dirty solution, I''ve put a Monitor() at messages arrived.
But I would like to finally got a nicer solution.

What do you think about the architecture I should make ?

Should I create and manage a Pool of MysqlConnection and only locking when
pool is fully occuped ?

Do you know already made solutions for that case ?

Thanks a lot for you comments and ideas,
cyrille.

PS: Before I put the ugly Monitor, I got some errors like :

Exception: Connection must be valid and open. StackTrace:
at MySql.Data.MySqlClient.MySqlCommand.CheckState()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader( CommandBehavior
behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader( )

Exception: Expected prepared statement marker. StackTrace:
at MySql.Data.MySqlClient.NativeDriver.Prepare(String sql, String[]
parmNames)
at MySql.Data.MySqlClient.MySqlCommand.Prepare()






Lloyd Dupont a écrit :

Hi Cyrille37

what''s wrong with the Monitor? I loos multi-threading processing of incoming messages.


err.... could you reword this sentence?
I don''t manage to guess its meaning....



Sorry for my bad english. I use my extra ball to try again :

With Monitor() at messages arriving, I lose the advantage of multi-threading.

Is that more readable ?
;o)
I have something like that (as an attached document of this answer).
Well it was a useless peace of code as SqlConnection already use a
connection pool under the hood.
But if you replace all the SqlConnection stuff by MySqlConnection it will
suddenly start to make sense!



THANKS A LOT !!!

Ok, I''ll try it this afternoon.

<;oP> I hope you''ve make a non buggy code </;oP>

I give you a report after tests...

Cheers,
cyrille


这篇关于Xml-Rpc + Mysql.NET =线程问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆