Home > Back-end >  Java multi-thread to get the data
Java multi-thread to get the data

Time:05-06

Code has finished, but want to know in a Java program, whether the custom data, the data to make the thread running in the thread,
For example:
Import the Java. Util. *;
Import the Java. Util. ArrayList;
Import the Java. Util. Scanner;

/* class shuru {
Public static void main (String [] args) {
Scanner sc=new Scanner (System. In);
System. The out. Print (" please enter the number of threads, and press enter to end ");
Int n=sc. NextInt ();
System. The out. Print (" please enter the number of papers, press enter to end ");
Int T=sc. NextInt (); }
} */


public class shareThread implements Runnable {
Public static void main (String [] args) {
Scanner sc=new Scanner (System. In);
System. The out. Print (" please enter the number of threads, and press enter to end ");
Int n=sc. NextInt ();
System. The out. Print (" please enter the number of papers, press enter to end ");
Int T=sc. NextInt (); }


//public static int n=10000;//the number of array digital
//public static int T=5;//the number of threads
Public static int [] ary=new int [n].
Public static int [] newAry=new int [n].//sorted array

//thread running
Public void the run () {
//System. Out. Println (ary [I]);
//System. Out. Println (Thread. The currentThread (). The getName ());


Synchronized (shareThread. Class) {
for(int i=1; I & lt;=T; I++) {
If (Thread. CurrentThread (). The getName () equals (" Thread "+ I)) {
Int [] newArray=work (I);
Int count=n/T * (I - 1);
for(int j=0; jNewAry [count]=newArray [j];
//System. Out. Println (+ + count);
//System. Out. Print (newArray [j] + "");
//System. Out. Println (newAry [count] + "");
count++;
}
}
}
}
}
This period of realization of the above the red?
  • Related