代碼已經搞完,但是想知道在一個java程式中,能否自定義資料,將資料傳到執行緒中讓執行緒運行。
例如:
import java.util.*;
import java.util.ArrayList;
import java.util.Scanner;
/*class shuru{
public static void main(String[] args){
Scanner sc= new Scanner(System.in);
System.out.print("請輸入執行緒數量,按回車結束");
int n=sc.nextInt();
System.out.print("請輸入卷子數量,按回車結束");
int T=sc.nextInt();}
}*/
public class shareThread implements Runnable{
public static void main(String[] args){
Scanner sc= new Scanner(System.in);
System.out.print("請輸入執行緒數量,按回車結束");
int n=sc.nextInt();
System.out.print("請輸入卷子數量,按回車結束");
int T=sc.nextInt();}
//public static int n = 10000; //陣列內數字的數量
//public static int T = 5; //執行緒數
public static int[] ary = new int[n];
public static int[] newAry = new int[n]; //排序后的陣列
//執行緒運行
public void run(){
//System.out.println(ary[i]);
//System.out.println(Thread.currentThread().getName());
synchronized(shareThread.class){
for(int i = 1; i <= T; i++){
if(Thread.currentThread().getName().equals("thread"+i)){
int[] newArray= work(i);
int count = n/T *(i-1);
for(int j = 0;j<newArray.length;j++){
newAry[count] = newArray[j];
//System.out.println(++count);
//System.out.print(newArray[j]+ " ");
//System.out.println(newAry[count] + "");
count++;
}
}
}
}
}
上述標紅的這段能否實作?
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/282965.html
標籤:Java相關
上一篇:資料庫用dcomnection,socketconnect,datasnap作為中間件有啥好處?
下一篇:there are no resource that can added or remove from the reserve
