Today I looked at the Java concurrency Program, wrote a starter program, and set the thread priority.
Class Elem implements runnable{public
static int id = 0;
private int cutdown = 5;
private int priority;
public void setpriority (int priority) {
this.priority = priority;
}
public int getpriority () {return
this.priority;
}
public void Run () {
thread.currentthread (). SetPriority (priority);
int threadId = id++;
while (cutdown--> 0) {
double d = 1.2;
while (D < 10000)
D = d + (MATH.E + Math.PI)/n;
System.out.println ("#" + ThreadId + "(" + Cutdown + ")");
}} public class Basic {public
static void Main (String args[]) {for
(int i = 0; i < i++) {
Elem e = new E Lem ();
if (i = = 0)
e.setpriority (thread.max_priority);
else
e.setpriority (thread.min_priority);
Thread t = new thread (e);
T.start ();}}
Because the machine is very strong, so start and do not see the effect of concurrency, the feeling is performed sequentially, so in the middle of the addition of floating-point arithmetic to delay time.
Of course, the main function can use executors to manage threads.
Import java.util.concurrent.*;
Class Elem implements runnable{public static int id = 0;
private int cutdown = 5;
private int priority;
public void setpriority (int priority) {this.priority = priority;
public int getpriority () {return this.priority;
public void Run () {Thread.CurrentThread (). SetPriority (priority);
int threadId = id++;
while (cutdown--> 0) {double d = 1.2;
while (D < 10000) d = d + (MATH.E + Math.PI)/n;
System.out.println ("#" + ThreadId + "(" + Cutdown + ")"); }} public class Basic {public static void main (String args[]) {//for (int i = 0; i < i++) {//Elem
E = new Elem ();
if (i = = 0)//e.setpriority (thread.max_priority);
else//e.setpriority (thread.min_priority);
Thread t = new thread (e);
T.start ();
Executorservice exec = Executors.newcachedthreadpool (); for (int i = 0; i < i++) {Elem e = newElem ();
if (i = = 0) e.setpriority (thread.max_priority);
else e.setpriority (thread.min_priority);
Exec.execute (e);
} exec.shutdown (); }
}