Barry Oglesby
1 min readMar 11, 2022

--

Hi. Thanks for the comment.

I made an assumption there that was not quite correct. I was assuming the Function was being executed by a Function Execution Processor thread, and thats not always the case.

I should have implemented that code something like this so the property is reset to what it was before the execution:

public void execute(FunctionContext context) {

InternalDistributedSystem ids = (InternalDistributedSystem) context.getCache().getDistributedSystem();

boolean threadsSocketPolicyBeforeExecution = !ids.threadOwnsResources();

System.out.println(Thread.currentThread().getName() + ": ThreadsSocketPolicyBeforeExecution=" + threadsSocketPolicyBeforeExecution);

DistributedSystem.setThreadsSocketPolicy(false);

try {

// Process request

} finally {

DistributedSystem.setThreadsSocketPolicy(threadsSocketPolicyBeforeExecution);

System.out.println(Thread.currentThread().getName() + ": ThreadsSocketPolicyAfterExecution=" + !ids.threadOwnsResources());

}

}

If the boolean passed into DistributedSystem.setThreadsSocketPolicy is true, then threadOwnsResources() returns false and vice versa.

If I run that Function, I see this behavior:

For ServerConnection threads:

ServerConnection on port 52399 Thread 1: ThreadsSocketPolicyBeforeExecution=false

ServerConnection on port 52399 Thread 1: ThreadsSocketPolicyAfterExecution=false

For Function Execution threads:

Function Execution Processor2: ThreadsSocketPolicyBeforeExecution=true

Function Execution Processor2: ThreadsSocketPolicyAfterExecution=true

Thanks for catching this.

--

--

Barry Oglesby
Barry Oglesby

No responses yet