FileDocCategorySizeDatePackage
LockingExample.javaAPI DocExample2978Mon Nov 09 12:45:52 GMT 1998None

LockingExample

public class LockingExample extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)


    // Create a document with some initial text
    Document doc = new PlainDocument();
    try {
      doc.insertString(0, "Three blind mice", null);
    } catch (BadLocationException ex) {ex.printStackTrace();}

    // Create two "renders" which will simulate painting the document
    DocRenderer r1 = new DocRenderer("One", doc);
    DocRenderer r2 = new DocRenderer("Two", doc);

    // Start the renders in new threads. We'll print out timing data to show how
    // things work
    long startTime = System.currentTimeMillis();
    r1.renderInThread(startTime);
    r2.renderInThread(startTime);

    // Wait one second before writing
    try {
      Thread.sleep(1000);
    } catch (InterruptedException ex) {}

    // Attempt to add some content to the document
    System.out.println("Start writing: "
      + (System.currentTimeMillis()-startTime));

    try {
      doc.insertString(doc.getLength(), ", see how they run.", null);
    } catch (BadLocationException ex) {ex.printStackTrace();}

    System.out.println("Done writing: "
      + (System.currentTimeMillis()-startTime));

    // Render the modified document
    r1.renderInThread(startTime);