从多个线程读取SQL数据 [英] read SQL data from multiple threads

查看:98
本文介绍了从多个线程读取SQL数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的任务-从SQL表读取数据,对其进行处理,并在完成后-更新DB中的一个字段(将处理设置为true),因此每个记录仅应处理一次.

I have a simple task - to read data from SQL table, process it, and once finished - update a field in DB (set processed=true), so every record should be processed only once.

您能告诉我,我可以使用什么技术来实现多线程?这意味着要从多个线程中的表中读取数据.

Can you advise me, what technique can I use to do it multi-threaded? It means, read data from table in multiple threads.

推荐答案

如果要读取多个线程中的数据而不重叠,则可以尝试分页.您可以让每个线程读取不同的页面.例如,您可以让第一个线程读取前20条记录,处理这些记录中的每条,然后为每条记录设置hanced = true,而第二个线程对接下来的20条记录执行相同的操作,依此类推.

If you want to read data in multiple threads without overlapping then you might try paging. You could have each thread read a different page. For example, you could have the first thread read the first 20 records, process each of those records, and then set processed=true for each, while the second thread is doing the same for the next 20 records and so on.

查看此链接,以获取有关在多个线程中分页的更多信息.

Check out this link for more info on paging in multiple threads. http://ericniemiec.wordpress.com/2010/06/10/paging-records-in-sql-server-2008-for-processing-database-records-on-different-threads-in-c/

这篇关于从多个线程读取SQL数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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