thread priority and eclipse
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));
} }
Re: thread priority and eclipse
Other projects are excellent running. Only this causes problems
Re: thread priority and eclipse
Please do not double post your question - I have removed your other post. In addition, please wrap your code in the code tags.
Your problem can be a great many things and you don't give us enough information. Can you compile and run without the IDE? Did you add some println's in there to see if the main method is entered?
Re: thread priority and eclipse
Yes. The main method is entered succesfull. But this programm can work only one effort. The next efforts the computer works badly
Re: thread priority and eclipse
I solved the problem. One must to write
Code :
catch (Exception e) {
}
lo.stop();
hi.stop();
instead of
Code :
catch (Exception e) {
lo.stop();
hi.stop();
}
because in the second the threads could not be finished