比如写50个线程同时insert 或update数据库,用java该怎么写呢,自己写了个运行不起来,还在调试,希望大家给我个例子,让我学习学习。谢谢。

解决方案 »

  1.   

    设计一个implements runnable的类
    在其中的执行方法中实现数据库操作另外一个执行类main函数中循环生成50个线程 start
      

  2.   

    这50哥线程怎么写?写在for循环里?
      

  3.   


       class threadclass implements Runnable{
       int tid = 0;
       public threadclass(int i){
          tid = i;
       }    public void run(){
           System.out.println(tid );
        }   }   public static void main(String[] args) throws Exception {
          for(int i = 0 ; i < 50 ;i++){
           threadclass t = new threadclass(i);
            new Thread(t).start();
          }
       }这是个例子