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(); } }这是个例子
在其中的执行方法中实现数据库操作另外一个执行类main函数中循环生成50个线程 start
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();
}
}这是个例子