Class ThreadTest

java.lang.Object
org.postgresql.pljava.example.annotation.ThreadTest
All Implemented Interfaces:
Runnable

@SQLAction(implementor="notFromDDR", requires="strictlyNestedTest fn", install="select strictlyNestedTest()") public class ThreadTest extends Object implements Runnable
Test control of access to 1-thread backend by n-thread JVM. The "select strictlyNestedTest()" is marked "notFromDDR" because it actually does deadlock when invoked from within install_jar, though it succeeds when invoked directly. The explanation may lie in the JNI spec's caveat that JNI MonitorEnter/MonitorExit functions must be paired with each other and not arbitrarily mixed with JVM monitorenter/monitorexit bytecodes. In the present design, that can happen (install_jar uses a synchronized block to call into the backend when executing DDR commands; DDR command calling strictlyNestedTest leads to JNI MonitorExit in BEGIN_CALL; perhaps that does not effectively release the lock taken by the synchronized block).
  • Constructor Details

  • Method Details

    • strictlyNestedTest

      @Function(provides="strictlyNestedTest fn") public static String strictlyNestedTest() throws SQLException
      Test that another thread can enter SPI while the calling thread is out. Create a thread that uses SPI to perform a query and set the value of result. Start and wait for that thread (so this one is clearly out of the backend the whole time), then return the result.
      Throws:
      SQLException
    • run

      public void run()
      Specified by:
      run in interface Runnable