Help with Threads in Java2D

Hi All,

This code is from the Java2D line examples
http://java.sun.com/products/java-media/2D/samples/suite/

Conversion of most of the sample code has gone well, but the threads
have thrown me into a state of confusion :slight_smile:
Any clues on how to code the following in JRuby. Google has not been
much help.
e.g. How to use syncronized in the stop method is one of my problems.

public void start() {
    thread = new Thread(this);
    thread.setPriority(Thread.MIN_PRIORITY);
    thread.start();
}


public synchronized void stop() {
    thread = null;
}


public void run() {
    Thread me = Thread.currentThread();
    while (thread == me) {
        repaint();
        try {
            thread.sleep(10);
        } catch (InterruptedException e) { break; }
    }
    thread = null;
}

Thanks

Paul F.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Paul F. wrote:

Hi All,

This code is from the Java2D line examples
http://java.sun.com/products/java-media/2D/samples/suite/

Conversion of most of the sample code has gone well, but the threads
have thrown me into a state of confusion :slight_smile:
Any clues on how to code the following in JRuby. Google has not been
much help.
e.g. How to use syncronized in the stop method is one of my problems.

The use of synchronized there is rather odd, since thread = null is
mostly dependent on the thread field being volatile. I wouldn’t worry
about that on the Ruby side…you can use that or some other
value/attribute as a trigger to shut down the thread.

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs