Hey
this is my first time posting on here
and excuse me for my english
I have a homework to explore how time of executings depends
on thread priority.
I maked this work in Eclipse. I don't know why my Eclipse have a problem with launching of this code. He don't want to launch. Eclipse is going down, the i push RUN.
I undestand that it is unreal, that my programm breaks Eclipse.
May you ask me the reason of such effect and estimate my code.
Thank
here is my code
class Vector implements Runnable {
static long click = 0;
private static long st;
long clickMax = 1000;
private Thread t;
private static Thread r;
Vector lo;
Vector hi;
private boolean keepRunning = true;
public Vector(int p){
t = new Thread(this);
t.setPriority(p);
}
public void run() {
while(keepRunning == true){
click++;
}
double end = System.currentTimeMillis();
double time = (end-st);
System.out.println(time);
}
public void start(){
t.start();
}
public void stop(){
keepRunning=false;
}
public static void main(String args[]) throws RuntimeException {
Thread.currentThread().setPriority(Thread.NORM_PRI ORITY);
r = Thread.currentThread();
Vector hi = new Vector(Thread.NORM_PRIORITY+2 );
Vector lo = new Vector(Thread.NORM_PRIORITY-2 );
st = System.currentTimeMillis();
hi.start();
lo.start();
try {
Thread.sleep(1000);
}
catch (Exception e) {
lo.stop();
hi.stop();
}
System.out.println("низкий приоритет "+lo.click + " высокий приоритет " + hi.click);
System.out.println("выс - низ " + (hi.click-lo.click));
} }