通过多线程的共享连接 [英] Shared connection over multiply threads

查看:177
本文介绍了通过多线程的共享连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以创建 DBClientConnection 的指针并在乘法线程中使用它?

  connection = new DBClientConnection(); 
connection-> connect(localhost);

然后在线程中使用 connection p>

同时访问连接是否安全?

解决方案

否。 DBClientConnection不是线程安全的,不应该与多个线程共享。您可能还需要检查ScopedDbConnection,它由连接池支持,并在销毁时为您关闭套接字。


Is it possible to create pointer of DBClientConnection and use it in multiply threads?

connection = new DBClientConnection();
connection->connect("localhost");

Then use connection in thread.

Is it safe to access to connection simultaneously?

解决方案

No. DBClientConnection is not thread safe and should not be shared with more than one thread. You might also want to check ScopedDbConnection, which is backed by a connection pool and closes the socket for you upon destruction.

这篇关于通过多线程的共享连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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