What does JavaLangAccess.blockedOn(Thread t, Interruptible b) do?

From public javadoc:

void blockedOn(Thread t, Interruptible b)

Set thread's blocker field.

I did stack with that method during java nio researching, particulary AbstractInterruptibleChannel source code

Answers


If you look at the OpenJDK it calls

/* The object in which this thread is blocked in an interruptible I/O
 * operation, if any.  The blocker's interrupt method should be invoked
 * after setting this thread's interrupt status.
 */
private volatile Interruptible blocker;
private Object blockerLock = new Object();

/* Set the blocker field; invoked via sun.misc.SharedSecrets from java.nio code
 */
void blockedOn(Interruptible b) {
synchronized (blockerLock) {
    blocker = b;
}
}

This is used to trigger an action when a thread is interrupted.


Seems, I did found answer in java.lang.Thread source code (Oracle/Sun JVM):

/* The object in which this thread is blocked in an interruptible I/O
 * operation, if any.  The blocker's interrupt method should be invoked
 * after setting this thread's interrupt status.
 */
private volatile Interruptible blocker;
private Object blockerLock = new Object();

/* Set the blocker field; invoked via sun.misc.SharedSecrets from java.nio code
 */
void blockedOn(Interruptible b) {
    synchronized (blockerLock) {
         blocker = b;
    }
}
public void interrupt() {
    if (this != Thread.currentThread())
        checkAccess();

    synchronized (blockerLock) {
        Interruptible b = blocker;
        if (b != null) {
        interrupt0();        // Just to set the interrupt flag
        b.interrupt();
        return;
        }
    }
    interrupt0();
}

So correct me if I wrong, my conclusions are:

  • Interruptible is just callback for Thread interruption event
  • Attach concrete interruptible instance to concrete class possible only with following code: sun.misc.SharedSecrets.getJavaLangAccess().blockedOn(threadInstance, intrInstance);

Need Your Help

MySQL DateSub inside loop

mysql loops

i have a storedprocedure like this :

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.