代码之家  ›  专栏  ›  技术社区  ›  TalentTuner

用c语言实现多线程搜索#

  •  2
  • TalentTuner  · 技术社区  · 14 年前

    我想在select语句中搜索超过15000个值,如下所示:

    select * from tableA where id in (1,2,3......16000)

    我可以在different select语句中使用threads(比如3左右)和partion 15000值吗。

    1. select * from tableA where id in (1,2,3......5000)
    2. select * from tableA where id in (5001....10000)
    3. select * from tableA where id in (10001....15000)

    并并行运行这3个select语句。

    3 回复  |  直到 14 年前
        1
  •  2
  •   Nate CSS Guy    14 年前

    是的,但真正的问题是为什么?

    像这样的事情可能会让你开始:

    var itms = new List<YourDataClass>();
    
    var thr1 = new Thread(new ThreadStart(delegate()
    {
        // select code
        // populate itms
    }));
    var thr2 = new Thread(new ThreadStart(delegate()
    {
        // select code
        // populate itms
    }));
    var thr3 = new Thread(new ThreadStart(delegate()
    {
        // select code
        // populate itms
    }));
    
    thr1.Start();
    thr2.Start();
    thr3.Start();
    

    但是,也就是说,如果您的id是整数并且(基于您的示例)的范围 IN where id > 1 and id < 16000 风格。这可能会有更好的表现。

        2
  •  1
  •   Song Gao    14 年前

    您可以尝试C#4.0的并行编程功能

    很简单:

    List<String> jobs = new List<String>();
    Parallel.ForEach(jobs, job=>
        {
            Foo(job);
        }
    );
    

    看看这个: http://msdn.microsoft.com/en-us/library/dd460720.aspx

        3
  •  0
  •   Ronald Wildenberg    14 年前

    IN 语句可能导致错误。