You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ga...@apache.org on 2019/08/05 09:34:42 UTC

[flink] 03/04: [FLINK-13384][runtime] Set context class loader before instantiating AbstractInvokable

This is an automated email from the ASF dual-hosted git repository.

gary pushed a commit to branch release-1.9
in repository https://gitbox.apache.org/repos/asf/flink.git

commit e2eb6d41a0abcc206966249d83ceb0f450b2cf6b
Author: Gary Yao <ga...@apache.org>
AuthorDate: Thu Aug 1 13:46:16 2019 +0200

    [FLINK-13384][runtime] Set context class loader before instantiating AbstractInvokable
    
    Set the user code class loader as the executing thread's context class loader
    before instantiating the AbstractInvokable so that the constructor of the
    AbstractInvokable implementation has access to the user code class loader.
---
 .../src/main/java/org/apache/flink/runtime/taskmanager/Task.java  | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/taskmanager/Task.java b/flink-runtime/src/main/java/org/apache/flink/runtime/taskmanager/Task.java
index 12049f2..7dafc4f 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/taskmanager/Task.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/taskmanager/Task.java
@@ -662,6 +662,11 @@ public class Task implements Runnable, TaskActions, PartitionProducerStateProvid
 				metrics,
 				this);
 
+			// Make sure the user code classloader is accessible thread-locally.
+			// We are setting the correct context class loader before instantiating the invokable
+			// so that it is available to the invokable during its entire lifetime.
+			executingThread.setContextClassLoader(userCodeClassLoader);
+
 			// now load and instantiate the task's invokable code
 			invokable = loadAndInstantiateInvokable(userCodeClassLoader, nameOfInvokableClass, env);
 
@@ -681,9 +686,6 @@ public class Task implements Runnable, TaskActions, PartitionProducerStateProvid
 			// notify everyone that we switched to running
 			taskManagerActions.updateTaskExecutionState(new TaskExecutionState(jobId, executionId, ExecutionState.RUNNING));
 
-			// make sure the user code classloader is accessible thread-locally
-			executingThread.setContextClassLoader(userCodeClassLoader);
-
 			// run the invokable
 			invokable.invoke();