我做一个东西,用了线程池实现多线程查询
select url,ids from myurl where ids>900 and ids<=1000
select url,ids from myurl where ids>700 and ids<=800
select url,ids from myurl where ids>0 and ids<=100
select url,ids from myurl where ids>300 and ids<=400
select url,ids from myurl where ids>100 and ids<=200
select url,ids from myurl where ids>200 and ids<=300
select url,ids from myurl where ids>400 and ids<=500
select url,ids from myurl where ids>500 and ids<=600
select url,ids from myurl where ids>600 and ids<=700
select url,ids from myurl where ids>800 and ids<=900
select url,ids from myurl where ids>1100 and ids<=1200
select url,ids from myurl where ids>1000 and ids<=1100
select url,ids from myurl where ids>1200 and ids<=1300
select url,ids from myurl where ids>1400 and ids<=1500
select url,ids from myurl where ids>1300 and ids<=1400
select url,ids from myurl where ids>1600 and ids<=1700
select url,ids from myurl where ids>1500 and ids<=1600
select url,ids from myurl where ids>1800 and ids<=1900
select url,ids from myurl where ids>2000 and ids<=2100
select url,ids from myurl where ids>1700 and ids<=1800
select url,ids from myurl where ids>1900 and ids<=2000
select url,ids from myurl where ids>2200 and ids<=2300
select url,ids from myurl where ids>2100 and ids<=2200
select url,ids from myurl where ids>2400 and ids<=2500
select url,ids from myurl where ids>2600 and ids<=2700
select url,ids from myurl where ids>2800 and ids<=2900
select url,ids from myurl where ids>3000 and ids<=3100
select url,ids from myurl where ids>2300 and ids<=2400
select url,ids from myurl where ids>2500 and ids<=2600
select url,ids from myurl where ids>2700 and ids<=2800
select url,ids from myurl where ids>2900 and ids<=3000
select url,ids from myurl where ids>3100 and ids<=3200
select url,ids from myurl where ids>3300 and ids<=3400
select url,ids from myurl where ids>3500 and ids<=3600
select url,ids from myurl where ids>3200 and ids<=3300
select url,ids from myurl where ids>3400 and ids<=3500
select url,ids from myurl where ids>3700 and ids<=3800
select url,ids from myurl where ids>3600 and ids<=3700
select url,ids from myurl where ids>3900 and ids<=4000
select url,ids from myurl where ids>3800 and ids<=3900
select url,ids from myurl where ids>4000 and ids<=4100
select url,ids from myurl where ids>4100 and ids<=4200
select url,ids from myurl where ids>4300 and ids<=4400
select url,ids from myurl where ids>4200 and ids<=4300
select url,ids from myurl where ids>4400 and ids<=4500
select url,ids from myurl where ids>4600 and ids<=4700
select url,ids from myurl where ids>4800 and ids<=4900
select url,ids from myurl where ids>4500 and ids<=4600
select url,ids from myurl where ids>4700 and ids<=4800
select url,ids from myurl where ids>4900 and ids<=5000
.
.
.
每个线程一条查询语句,现在的问题是线程池15个以下就行,并发15个以上就不行,也没有错误就是不出结果少于15个马上有输出结果。可能
是死锁了,问:怎么查一个表不出现死锁呢?不做修改只查询,sql server的并发用户数改成0了也没用,就这条查询语句怎么改呢?

解决方案 »

  1.   

    SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
      

  2.   

    SELECT * FROM TB WITH (TABLOCK)?
      

  3.   

    SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED貌似不行啊,问什么不提交呢?我想不明白,我只是查询,又不是修改
      

  4.   


    select url,ids from myurl where ids>900 and ids<=1000 UNION ALL
    select url,ids from myurl where ids>700 and ids<=800 UNION ALL
    select url,ids from myurl where ids>0 and ids<=100  UNION ALL
    select url,ids from myurl where ids>300 and ids<=400
    ....在具体做的时候再进行处理...批量进行
      

  5.   

    select url,ids from myurl where ids>300 and ids<=400这是一个线程中的查询语句,就这么一句
      

  6.   


    select url,ids from myurl where ids>300 and ids <=400  WITH(TABLOCK)
    这样试试
      

  7.   

    已解决!好像并发很多没有问题的!但是,前提是不能同时申请获得sql server链接15个以上就不行,构建线程池时,初始化好连接就行。如果不初始化连接,线程池使用时,并发15个以上同时申请获取连接还是不行。