程序需要对多台数据库服务器做相同的工作
数据库的连接放在配置文件中。
我想对每台数据库服务器开N个线程进行操作
我想做到在配置文件中设置数据库服务器的数量和连接串,
程序启动时能自动开启读取配置,如有3个服务器的配置就开3*N个线程进行工作
并将连接串赋给相应的线程
为了便于管理想用2维数组 Thread[][] 来进行管理可以实现吗?如何进行初始化?

解决方案 »

  1.   

    Thread[][] ts = new Thread[x][y];for(int i =0 ;i < x;i++)
    {
       for(int j = 0; j<y;j++)
       {
          ts[i][j] = new Thread(new ThreadStart(XXXX));
          ts[i][j].Start();
          ......
       }
    }
      

  2.   

    Thread[][] ts = new Thread[4][5]; 
    这句编译报错  Error 1 Invalid rank specifier: expected ',' or ']'
      

  3.   

    You might need to use multidimensional array.
    Thread[,] ts = new Thread[3,4];But I think you can use OO to do this work.
    static partial class Program
    {
        static partial void Run(string[] args)
        {
            IEnumerable<Server> servers = GetServers();
            foreach (var server in servers)
            {
                server.Run();
            }
        }    private static IEnumerable<Server> GetServers()
        {
            return null; // replace here with your code
        }
    }// you can even modify the class to make it accept parameters
    public class Worker
    {
        private readonly Thread thread = new Thread(ThreadWorker);    public void Run()
        {
            this.thread.Start();
        }    private static void ThreadWorker() { /* replace here with your code */ }
    }public class Server
    {
        public Server() : this(null) { }
        public Server(IEnumerable<Worker> workers)
        {
            if (workers == null)
                this.Workers = new List<Worker>();
            else
                this.Workers = new List<Worker>(workers);
        }    public IList<Worker> Workers { get; private set; }    public void Run()
        {
            foreach (var worker in this.Workers)
            {
                worker.Run();
            }
        }
    }
      

  4.   

    为什么要用二维数组呢。用arraylist和一个hashtable 感觉更好点。。
    有现成的容器类可以使用,就别自己造轮子了arraylist 管理一个服务器上的n个线程 。
    hashtable管理服务器把arraylist 做为value 放到hashtable 中去。。
      

  5.   

    一个数组(包括array、List等各种容器)存放服务器对象,服务器对象有个数组存放连接线程