Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: thread priority and eclipse

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Location
    Perm, Russia
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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));



    } }


  2. #2
    Junior Member
    Join Date
    Jun 2011
    Location
    Perm, Russia
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: thread priority and eclipse

    Other projects are excellent running. Only this causes problems

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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?

  4. #4
    Junior Member
    Join Date
    Jun 2011
    Location
    Perm, Russia
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  5. #5
    Junior Member
    Join Date
    Jun 2011
    Location
    Perm, Russia
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: thread priority and eclipse

    I solved the problem. One must to write
    catch (Exception e) {
     
    }
    lo.stop();
    hi.stop();
    instead of
    catch (Exception e) {
    lo.stop();
    hi.stop();
    }

    because in the second the threads could not be finished

Similar Threads

  1. Threads priority: low priority run faster than high priority
    By leonixyz in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 8th, 2011, 04:33 PM
  2. Priority Queue help
    By BuhRock in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 3rd, 2011, 06:37 PM
  3. Priority Queue using comparable
    By jkalm in forum Collections and Generics
    Replies: 6
    Last Post: December 5th, 2010, 10:02 PM
  4. Replies: 4
    Last Post: July 21st, 2010, 04:07 PM